Extract page layout
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user