added region support, fixed minor bugs
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
4807355add
commit
77b88325cf
8 changed files with 121 additions and 16 deletions
|
@ -18,6 +18,8 @@ func NewHandler(store steamServer.Store) *Handler {
|
|||
h.Use(middleware.Logger)
|
||||
|
||||
h.Get("/", h.Home())
|
||||
h.Get("/europe", h.Europe())
|
||||
h.Get("/america", h.America())
|
||||
|
||||
return h
|
||||
}
|
||||
|
@ -46,3 +48,53 @@ func (h *Handler) Home() http.HandlerFunc {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) Europe() http.HandlerFunc {
|
||||
type data struct {
|
||||
Servers []steamServer.Server
|
||||
}
|
||||
|
||||
|
||||
|
||||
tmpl := template.Must(template.ParseFiles("templates/home.html"))
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
reg, err := h.store.Region("Europe")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
ss, err := h.store.ServersByRegion(reg.ID)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl.Execute(w, data {
|
||||
Servers: ss,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) America() http.HandlerFunc {
|
||||
type data struct {
|
||||
Servers []steamServer.Server
|
||||
}
|
||||
|
||||
tmpl := template.Must(template.ParseFiles("templates/home.html"))
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
reg, err := h.store.Region("North America")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
ss, err := h.store.ServersByRegion(reg.ID)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl.Execute(w, data {
|
||||
Servers: ss,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue