diff --git a/server/server.go b/server/server.go index 7992fba..2de01b5 100644 --- a/server/server.go +++ b/server/server.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "os/signal" + "strconv" "time" "github.com/golang-migrate/migrate/v4" @@ -23,6 +24,14 @@ var conf config.Config var templates *template.Template +var funcMap = template.FuncMap{ + "sub": sub, +} + +func sub(a, b int64) string { + return strconv.FormatInt(a-b, 10) +} + var db *pgxpool.Pool func Start(_conf config.Config, tmplFS embed.FS, staticFS embed.FS, migrationsFS embed.FS) { @@ -33,7 +42,9 @@ func Start(_conf config.Config, tmplFS embed.FS, staticFS embed.FS, migrationsFS fs := http.FileServer(staticServer) // Templates - t, err := template.ParseFS(tmplFS, "tmpl/*.tmpl") + t := template.New("") + t.Funcs(funcMap) + t, err := t.ParseFS(tmplFS, "tmpl/*.tmpl") if err != nil { panic(fmt.Errorf("Parsing templates: %w", err)) } diff --git a/tmpl/index.tmpl b/tmpl/index.tmpl index 644beba..58809db 100644 --- a/tmpl/index.tmpl +++ b/tmpl/index.tmpl @@ -1,7 +1,18 @@ {{template "head"}}