Extract page layout
This commit is contained in:
+5
-8
@@ -5,7 +5,6 @@ import (
|
||||
"net/http"
|
||||
|
||||
"pool-stats/database"
|
||||
"pool-stats/helpers"
|
||||
"pool-stats/models"
|
||||
)
|
||||
|
||||
@@ -14,13 +13,10 @@ type IndexPageData struct {
|
||||
}
|
||||
|
||||
func (ws *WebServer) IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl := template.New("index").Funcs(template.FuncMap{
|
||||
"humanDiff": helpers.HumanDiff,
|
||||
"formatCreateDate": helpers.FormatCreateDate,
|
||||
})
|
||||
tmpl, err := tmpl.ParseFiles("templates/index.html")
|
||||
tmpl, err := template.Must(ws.templates.Clone()).ParseFiles("templates/index.html")
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to load template", 500)
|
||||
http.Error(w, "Failed to parse template", 500)
|
||||
println("Error parsing template:", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -33,7 +29,8 @@ func (ws *WebServer) IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
indexData := IndexPageData{
|
||||
Stats: tws,
|
||||
}
|
||||
if err := tmpl.Execute(w, indexData); err != nil {
|
||||
|
||||
if err := tmpl.ExecuteTemplate(w, "index.html", indexData); err != nil {
|
||||
http.Error(w, "Failed to render template", 500)
|
||||
println("Error rendering template:", err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user