-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhandlers.go
42 lines (36 loc) · 1019 Bytes
/
handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"log"
"net/http"
"strconv"
"github.com/gorilla/mux"
)
// landingHandler handles requests to "/"
func landingHandler(w http.ResponseWriter, r *http.Request) {
renderContent("tmpl/landing.html", r, w, nil)
}
// achievementHandler handles requests of the form "/{username}".
func achievementHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
username := vars["username"]
// Did the user supply their SteamID?
userID, err := strconv.Atoi(username)
if err != nil || len(username) != 17 {
// Nope, that must have been their profile name. Let's try
// that instead.
userID, err = getUserID(username)
}
if err != nil {
log.Println(err)
renderContent("tmpl/usernotfound.html", r, w, nil)
return
}
unearned, err := unearnedAchievements(userID)
if err != nil {
log.Println(err)
renderContent("tmpl/usernotfound.html", r, w, nil)
return
}
categorized := categorizeAchievements(unearned)
renderContent("tmpl/achievements.html", r, w, categorized)
}