Show version globally

This commit is contained in:
Erikas 2024-07-14 18:49:10 +03:00
parent 2c645881d4
commit 0222b03ebd
3 changed files with 25 additions and 6 deletions

View File

@ -11,6 +11,10 @@ var (
) )
func main() { func main() {
if version == "" {
version = "dev"
}
c, err := flightlesssomething.NewConfig() c, err := flightlesssomething.NewConfig()
if err != nil { if err != nil {
log.Fatalln("Failed to get config:", err) log.Fatalln("Failed to get config:", err)
@ -21,5 +25,5 @@ func main() {
return return
} }
flightlesssomething.Start(c) flightlesssomething.Start(c, version)
} }

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"html/template" "html/template"
"io/fs" "io/fs"
"log"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
@ -29,7 +30,7 @@ var (
benchmarksDir string benchmarksDir string
) )
func Start(c *Config) { func Start(c *Config, version string) {
// Setup data dir // // Setup data dir //
_, err := os.Stat(c.DataDir) _, err := os.Stat(c.DataDir)
@ -78,8 +79,21 @@ func Start(c *Config) {
r := gin.Default() r := gin.Default()
r.Use(sessions.Sessions("mysession", store)) r.Use(sessions.Sessions("mysession", store))
// Parse the embedded templates // Create a new FuncMap and add the version function
tmpl := template.Must(template.ParseFS(templatesFS, "templates/*.tmpl")) 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) r.SetHTMLTemplate(tmpl)
// Serve static files // Serve static files

View File

@ -12,9 +12,10 @@
<div class="container"> <div class="container">
<nav class="navbar navbar-expand-lg bg-body-tertiary rounded" aria-label="Eleventh navbar example"> <nav class="navbar navbar-expand-lg bg-body-tertiary rounded" aria-label="Eleventh navbar example">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" href="/benchmarks"> <a class="navbar-brand" href="/benchmarks" style="position: relative; display: inline-block;">
<i class="fa-solid fa-dove"></i> <i class="fa-solid fa-dove"></i>
FlightlessSomething FlightlessSomething
<small style="font-size: 0.5em; color: gray; position: absolute; top: 3em; left: 2.65em;">{{ version }}</small>
</a> </a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarsExample09" aria-controls="navbarsExample09" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarsExample09" aria-controls="navbarsExample09" aria-expanded="false" aria-label="Toggle navigation">