package web import ( "html/template" "net/http" "git.snrd.de/Spaenny/steamServer" "github.com/go-chi/chi" "github.com/go-chi/chi/middleware" ) func NewHandler(store steamServer.Store) *Handler { h := &Handler { Mux: chi.NewMux(), store: store, } h.Use(middleware.Logger) h.Get("/", h.Home()) return h } type Handler struct { *chi.Mux store steamServer.Store } func (h *Handler) Home() http.HandlerFunc { type data struct { Servers []steamServer.Server } tmpl := template.Must(template.ParseFiles("templates/home.html")) return func(w http.ResponseWriter, r *http.Request) { ss, err := h.store.Servers() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } tmpl.Execute(w, data { Servers: ss, }) } }