add 1 to index for high score rank

This commit is contained in:
shawnps
2015-02-08 10:49:36 -08:00
parent 338e593630
commit f4ac915aab
2 changed files with 7 additions and 7 deletions

View File

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

View File

@@ -60,7 +60,7 @@
<tbody>
{{ range $index, $highScore := .HighScores }}
<tr>
<td>{{ $index }}</td>
<td>{{ add $index 1 }}</td>
<td><a href="https://github.com/{{ $highScore.Repo }}" rel="nofollow">{{ $highScore.Repo }}</a></td>
<td>{{ $highScore.Files }}</td>
<td>{{ $highScore.Average }}</td>