diff --git a/handlers/high_scores.go b/handlers/high_scores.go index 6736a57..d4ab6ee 100644 --- a/handlers/high_scores.go +++ b/handlers/high_scores.go @@ -21,15 +21,9 @@ func formatScore(x float64) string { } // HighScoresHandler handles the stats page -func HighScoresHandler(w http.ResponseWriter, r *http.Request) { - db, err := badger.Open(badger.DefaultOptions("/tmp/badger")) - if err != nil { - log.Fatal(err) - } - defer db.Close() - +func HighScoresHandler(w http.ResponseWriter, r *http.Request, db *badger.DB) { count, scores := 0, &ScoreHeap{} - err = db.View(func(txn *badger.Txn) error { + err := db.View(func(txn *badger.Txn) error { var scoreBytes = []byte("[]") item, err := txn.Get([]byte("scores")) diff --git a/main.go b/main.go index 58975ab..6527559 100644 --- a/main.go +++ b/main.go @@ -119,7 +119,7 @@ func main() { http.HandleFunc(m.instrument("/checks", injectBadgerHandler(db, handlers.CheckHandler))) http.HandleFunc(m.instrument("/report/", makeHandler(db, "report", handlers.ReportHandler))) http.HandleFunc(m.instrument("/badge/", makeHandler(db, "badge", handlers.BadgeHandler))) - http.HandleFunc(m.instrument("/high_scores/", handlers.HighScoresHandler)) + http.HandleFunc(m.instrument("/high_scores/", injectBadgerHandler(db, handlers.HighScoresHandler))) http.HandleFunc(m.instrument("/supporters/", handlers.SupportersHandler)) http.HandleFunc(m.instrument("/about/", handlers.AboutHandler)) http.HandleFunc(m.instrument("/", injectBadgerHandler(db, handlers.HomeHandler)))