diff --git a/cmd/flightlesssomething/main.go b/cmd/flightlesssomething/main.go index 4bc6cda..11da360 100644 --- a/cmd/flightlesssomething/main.go +++ b/cmd/flightlesssomething/main.go @@ -11,6 +11,10 @@ var ( ) func main() { + if version == "" { + version = "dev" + } + c, err := flightlesssomething.NewConfig() if err != nil { log.Fatalln("Failed to get config:", err) @@ -21,5 +25,5 @@ func main() { return } - flightlesssomething.Start(c) + flightlesssomething.Start(c, version) } diff --git a/server.go b/server.go index b2d418f..fd5c0b9 100644 --- a/server.go +++ b/server.go @@ -5,6 +5,7 @@ import ( "fmt" "html/template" "io/fs" + "log" "net/http" "os" "path/filepath" @@ -29,7 +30,7 @@ var ( benchmarksDir string ) -func Start(c *Config) { +func Start(c *Config, version string) { // Setup data dir // _, err := os.Stat(c.DataDir) @@ -78,8 +79,21 @@ func Start(c *Config) { r := gin.Default() r.Use(sessions.Sessions("mysession", store)) - // Parse the embedded templates - tmpl := template.Must(template.ParseFS(templatesFS, "templates/*.tmpl")) + // Create a new FuncMap and add the version function + funcMap := template.FuncMap{ + "version": func() string { + return version + }, + } + + // Create a new template, apply the function map, and parse the templates + tmpl := template.New("").Funcs(funcMap) + tmpl, err = tmpl.ParseFS(templatesFS, "templates/*.tmpl") + if err != nil { + log.Fatalf("Failed to parse templates: %v", err) + } + + // Set the HTML template for Gin r.SetHTMLTemplate(tmpl) // Serve static files diff --git a/templates/header.tmpl b/templates/header.tmpl index da4e686..faea327 100644 --- a/templates/header.tmpl +++ b/templates/header.tmpl @@ -12,9 +12,10 @@