feat: show version in footer

This commit is contained in:
Tine 2024-06-07 11:43:32 +02:00
parent 77d1cfbc81
commit cf1d26100b
Signed by: mentos1386
SSH key fingerprint: SHA256:MNtTsLbihYaWF8j1fkOHfkKNlnN1JQfxEU/rBU8nCGw
5 changed files with 24 additions and 17 deletions

View file

@ -73,7 +73,7 @@ func main() {
if startServer {
slog.Info("Setting up Server")
cfg := config.NewServerConfig()
server, err := server.NewServer(cfg)
server, err := server.NewServer(version, cfg)
if err != nil {
slog.Error("Unable to create server", "error", err)
os.Exit(1)

View file

@ -14,18 +14,20 @@ import (
)
type Server struct {
echo *echo.Echo
cfg *config.ServerConfig
logger *slog.Logger
echo *echo.Echo
cfg *config.ServerConfig
logger *slog.Logger
version string
worker *Worker
}
func NewServer(cfg *config.ServerConfig) (*Server, error) {
func NewServer(version string, cfg *config.ServerConfig) (*Server, error) {
return &Server{
cfg: cfg,
echo: echo.New(),
logger: slog.Default(),
cfg: cfg,
echo: echo.New(),
logger: slog.Default(),
version: version,
}, nil
}
@ -51,7 +53,7 @@ func (s *Server) Start() error {
s.worker = NewWorker(temporalClient, s.cfg, s.logger, sqliteDb, kvStore)
templates, err := templates.NewTemplates(s.logger)
templates, err := templates.NewTemplates(s.version, s.logger)
if err != nil {
return errors.Wrap(err, "failed to create templates")
}

View file

@ -16,7 +16,7 @@ import (
func NewServer(l *slog.Logger, cfg *config.Config, tokenKeyProvider authorization.TokenKeyProvider) (t.Server, error) {
logger := slogLogger{
log: l,
level: slog.LevelDebug,
level: slog.LevelInfo,
}
sqlConfig := cfg.Persistence.DataStores[PersistenceStoreName].SQL

View file

@ -39,7 +39,9 @@
{{ template "main" . }}
<div class="container mx-auto">
<footer class="text-center text-gray-600 text-xs mt-8 mb-4">
<a class="hover:underline" href="https://zdravko.mnts.dev">Zdravko</a>
<a class="hover:underline" href="https://zdravko.mnts.dev"
>Zdravko {{ Version }}</a
>
-
<a
class="hover:underline"

View file

@ -23,7 +23,7 @@ type Templates struct {
templates map[string]*template.Template
}
func load(files ...string) *template.Template {
func load(version string, files ...string) *template.Template {
files = append(files, base)
t := template.New("default").Funcs(
@ -44,17 +44,20 @@ func load(files ...string) *template.Template {
"Now": time.Now,
"ScriptUnescapeString": script.UnescapeString,
"ScriptEscapeString": script.EscapeString,
"Version": func() string {
return version
},
})
return template.Must(t.ParseFS(templates, files...))
}
func loadSettings(files ...string) *template.Template {
func loadSettings(version string, files ...string) *template.Template {
files = append(files, "components/settings.tmpl")
return load(files...)
return load(version, files...)
}
func NewTemplates(logger *slog.Logger) (*Templates, error) {
func NewTemplates(version string, logger *slog.Logger) (*Templates, error) {
t := Templates{
logger: logger,
templates: map[string]*template.Template{},
@ -69,9 +72,9 @@ func NewTemplates(logger *slog.Logger) (*Templates, error) {
pathWithoutPrefix := strings.TrimPrefix(path, "pages/")
if strings.Contains(path, "settings") {
t.templates[pathWithoutPrefix] = loadSettings(path)
t.templates[pathWithoutPrefix] = loadSettings(version, path)
} else {
t.templates[pathWithoutPrefix] = load(path)
t.templates[pathWithoutPrefix] = load(version, path)
}
}
return nil