Extract page layout
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"pool-stats/database"
|
||||
"pool-stats/helpers"
|
||||
"pool-stats/models"
|
||||
)
|
||||
|
||||
@@ -13,13 +12,10 @@ type TopSharesPageData struct {
|
||||
}
|
||||
|
||||
func (ws *WebServer) TopSharesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl := template.New("top_shares").Funcs(template.FuncMap{
|
||||
"humanDiff": helpers.HumanDiff,
|
||||
"formatCreateDate": helpers.FormatCreateDate,
|
||||
})
|
||||
tmpl, err := tmpl.ParseFiles("templates/top_shares.html")
|
||||
tmpl, err := template.Must(ws.templates.Clone()).ParseFiles("templates/top_shares.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
|
||||
}
|
||||
|
||||
@@ -32,7 +28,7 @@ func (ws *WebServer) TopSharesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
data := TopSharesPageData{
|
||||
Shares: topShares,
|
||||
}
|
||||
if err := tmpl.Execute(w, data); err != nil {
|
||||
if err := tmpl.ExecuteTemplate(w, "top_shares.html", data); err != nil {
|
||||
http.Error(w, "Failed to render template", 500)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user