Show version globally
This commit is contained in:
parent
2c645881d4
commit
0222b03ebd
@ -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)
|
||||
}
|
||||
|
20
server.go
20
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
|
||||
|
@ -12,9 +12,10 @@
|
||||
<div class="container">
|
||||
<nav class="navbar navbar-expand-lg bg-body-tertiary rounded" aria-label="Eleventh navbar example">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/benchmarks">
|
||||
<i class="fa-solid fa-dove"></i>
|
||||
<a class="navbar-brand" href="/benchmarks" style="position: relative; display: inline-block;">
|
||||
<i class="fa-solid fa-dove"></i>
|
||||
FlightlessSomething
|
||||
<small style="font-size: 0.5em; color: gray; position: absolute; top: 3em; left: 2.65em;">{{ version }}</small>
|
||||
</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">
|
||||
|
Loading…
Reference in New Issue
Block a user