fixed displaying empty tables

This commit is contained in:
Philipp 2021-09-24 13:19:44 +02:00
parent 19e94f036e
commit 47a14e6b82
6 changed files with 268 additions and 11 deletions

View file

@ -20,6 +20,8 @@ func NewHandler(store steamServer.Store) *Handler {
h.Get("/", h.Home())
h.Get("/europe", h.Europe())
h.Get("/america", h.America())
h.Get("/australia", h.Australia())
h.Get("/asia", h.Asia())
return h
}
@ -58,7 +60,7 @@ func (h *Handler) Home() http.HandlerFunc {
}
tmpl.Execute(w, data {
Region: "All Regions - Serverlist",
Region: "All Regions",
Servers: ss,
Gamemodes: gg,
Flags: ff,
@ -71,10 +73,11 @@ func (h *Handler) Europe() http.HandlerFunc {
Region string
Servers []steamServer.Server
Gamemodes []steamServer.Gamemode
GamemodeCount []steamServer.GamemodeCount
Flags []steamServer.Flag
}
tmpl := template.Must(template.ParseFiles("templates/home.html"))
tmpl := template.Must(template.ParseFiles("templates/region.html"))
return func(w http.ResponseWriter, r *http.Request) {
reg, err := h.store.Region("Europe")
if err != nil {
@ -97,27 +100,32 @@ func (h *Handler) Europe() http.HandlerFunc {
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
c, err := h.store.GamemodeCount(reg.ID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
tmpl.Execute(w, data {
Region: "Europe",
Servers: ss,
Gamemodes: gg,
GamemodeCount: c,
Flags: ff,
})
}
}
func (h *Handler) America() http.HandlerFunc {
type data struct {
Region string
Servers []steamServer.Server
Gamemodes []steamServer.Gamemode
GamemodeCount []steamServer.GamemodeCount
Flags []steamServer.Flag
}
tmpl := template.Must(template.ParseFiles("templates/home.html"))
tmpl := template.Must(template.ParseFiles("templates/region.html"))
return func(w http.ResponseWriter, r *http.Request) {
reg, err := h.store.Region("North America")
if err != nil {
@ -141,10 +149,112 @@ func (h *Handler) America() http.HandlerFunc {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
c, err := h.store.GamemodeCount(reg.ID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
tmpl.Execute(w, data {
Region: "North America",
Servers: ss,
Gamemodes: gg,
GamemodeCount: c,
Flags: ff,
})
}
}
func (h *Handler) Asia() http.HandlerFunc {
type data struct {
Region string
Servers []steamServer.Server
Gamemodes []steamServer.Gamemode
GamemodeCount []steamServer.GamemodeCount
Flags []steamServer.Flag
}
tmpl := template.Must(template.ParseFiles("templates/region.html"))
return func(w http.ResponseWriter, r *http.Request) {
reg, err := h.store.Region("Asia")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
gg, err := h.store.Gamemodes()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
ss, err := h.store.ServersByRegion(reg.ID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
ff, err := h.store.Flags()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
c, err := h.store.GamemodeCount(reg.ID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
tmpl.Execute(w, data {
Region: "Asia",
Servers: ss,
Gamemodes: gg,
GamemodeCount: c,
Flags: ff,
})
}
}
func (h *Handler) Australia() http.HandlerFunc {
type data struct {
Region string
Servers []steamServer.Server
Gamemodes []steamServer.Gamemode
GamemodeCount []steamServer.GamemodeCount
Flags []steamServer.Flag
}
tmpl := template.Must(template.ParseFiles("templates/region.html"))
return func(w http.ResponseWriter, r *http.Request) {
reg, err := h.store.Region("Australia")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
gg, err := h.store.Gamemodes()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
ss, err := h.store.ServersByRegion(reg.ID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
ff, err := h.store.Flags()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
c, err := h.store.GamemodeCount(reg.ID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
tmpl.Execute(w, data {
Region: "Australia",
Servers: ss,
Gamemodes: gg,
GamemodeCount: c,
Flags: ff,
})
}