From f4ac915aabb719f0ccddbe8d02b50bee7b25b872 Mon Sep 17 00:00:00 2001 From: shawnps Date: Sun, 8 Feb 2015 10:49:36 -0800 Subject: [PATCH] add 1 to index for high score rank --- handlers/high_scores.go | 12 ++++++------ templates/high_scores.html | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/handlers/high_scores.go b/handlers/high_scores.go index a634698..fe6520d 100644 --- a/handlers/high_scores.go +++ b/handlers/high_scores.go @@ -9,6 +9,10 @@ import ( "gopkg.in/mgo.v2/bson" ) +func add(x, y int) int { + return x + y +} + var highScores []struct { Repo string Files int @@ -31,12 +35,8 @@ func HighScoresHandler(w http.ResponseWriter, r *http.Request) { return } - t, err := template.New("high_scores.html").ParseFiles("templates/high_scores.html") - if err != nil { - log.Println("ERROR: ", 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}) } diff --git a/templates/high_scores.html b/templates/high_scores.html index 348fcb4..21b3300 100644 --- a/templates/high_scores.html +++ b/templates/high_scores.html @@ -60,7 +60,7 @@ {{ range $index, $highScore := .HighScores }} - {{ $index }} + {{ add $index 1 }} {{ $highScore.Repo }} {{ $highScore.Files }} {{ $highScore.Average }}