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"
|
||||
"strconv"
|
||||
)
|
||||
@@ -16,15 +15,10 @@ type SharePageData struct {
|
||||
}
|
||||
|
||||
func (ws *WebServer) SharesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl := template.New("share_list").Funcs(template.FuncMap{
|
||||
"add": func(a, b int) int { return a + b },
|
||||
"sub": func(a, b int) int { return a - b },
|
||||
"humanDiff": helpers.HumanDiff,
|
||||
"formatCreateDate": helpers.FormatCreateDate,
|
||||
})
|
||||
tmpl, err := tmpl.ParseFiles("templates/shares.html")
|
||||
tmpl, err := template.Must(ws.templates.Clone()).ParseFiles("templates/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
|
||||
}
|
||||
|
||||
@@ -52,7 +46,7 @@ func (ws *WebServer) SharesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Page: offset/entriesPerPage + 1,
|
||||
HasMore: len(shareLogs) == entriesPerPage,
|
||||
}
|
||||
if err := tmpl.Execute(w, data); err != nil {
|
||||
if err := tmpl.ExecuteTemplate(w, "shares.html", data); err != nil {
|
||||
http.Error(w, "Failed to render template", 500)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user