diff --git a/handlers/high_scores.go b/handlers/high_scores.go index fe6520d..1ce0f1d 100644 --- a/handlers/high_scores.go +++ b/handlers/high_scores.go @@ -13,13 +13,13 @@ func add(x, y int) int { return x + y } -var highScores []struct { - Repo string - Files int - Average float64 -} - func HighScoresHandler(w http.ResponseWriter, r *http.Request) { + var highScores []struct { + Repo string + Files int + Average float64 + } + db := db.Mongo{URL: mongoURL, Database: mongoDatabase, CollectionName: mongoCollection} coll, err := db.Collection() if err != nil { @@ -35,8 +35,15 @@ func HighScoresHandler(w http.ResponseWriter, r *http.Request) { return } + count, err := coll.Count() + if err != nil { + log.Println("ERROR: could not get high scores: ", err) + http.Error(w, err.Error(), 500) + return + } + funcs := template.FuncMap{"add": add} t := template.Must(template.New("high_scores.html").Funcs(funcs).ParseFiles("templates/high_scores.html")) - t.Execute(w, map[string]interface{}{"HighScores": highScores}) + t.Execute(w, map[string]interface{}{"HighScores": highScores, "Count": count}) } diff --git a/templates/high_scores.html b/templates/high_scores.html index 21b3300..ced494f 100644 --- a/templates/high_scores.html +++ b/templates/high_scores.html @@ -68,6 +68,10 @@ {{end}} +

Stats

+