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 }}