Extract page layout

This commit is contained in:
Pijus Kamandulis
2025-06-23 18:42:00 +03:00
parent be637f4540
commit f66fbcc454
8 changed files with 190 additions and 282 deletions

View File

@@ -1,7 +1,9 @@
package web
import (
"html/template"
"net/http"
"pool-stats/helpers"
"fmt"
@@ -9,14 +11,27 @@ import (
)
type WebServer struct {
db *clover.DB
port int
db *clover.DB
port int
templates *template.Template
}
func NewWebServer(db *clover.DB, port int) *WebServer {
templates := template.New("base").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,
})
templates = template.Must(templates.ParseFiles(
"templates/layout.html",
))
return &WebServer{
db: db,
port: port,
db: db,
port: port,
templates: templates,
}
}