mirror of
https://github.com/gojp/goreportcard.git
synced 2026-01-28 22:39:05 +08:00
inject badger db into handlers part 2
This commit is contained in:
@@ -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"))
|
||||
|
||||
|
||||
2
main.go
2
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)))
|
||||
|
||||
Reference in New Issue
Block a user