mirror of
https://github.com/mentos1386/zdravko.git
synced 2024-11-27 17:51:23 +00:00
feat: show version in footer
This commit is contained in:
parent
77d1cfbc81
commit
cf1d26100b
5 changed files with 24 additions and 17 deletions
|
@ -73,7 +73,7 @@ func main() {
|
||||||
if startServer {
|
if startServer {
|
||||||
slog.Info("Setting up Server")
|
slog.Info("Setting up Server")
|
||||||
cfg := config.NewServerConfig()
|
cfg := config.NewServerConfig()
|
||||||
server, err := server.NewServer(cfg)
|
server, err := server.NewServer(version, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Unable to create server", "error", err)
|
slog.Error("Unable to create server", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -14,18 +14,20 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
echo *echo.Echo
|
echo *echo.Echo
|
||||||
cfg *config.ServerConfig
|
cfg *config.ServerConfig
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
|
version string
|
||||||
|
|
||||||
worker *Worker
|
worker *Worker
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(cfg *config.ServerConfig) (*Server, error) {
|
func NewServer(version string, cfg *config.ServerConfig) (*Server, error) {
|
||||||
return &Server{
|
return &Server{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
echo: echo.New(),
|
echo: echo.New(),
|
||||||
logger: slog.Default(),
|
logger: slog.Default(),
|
||||||
|
version: version,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +53,7 @@ func (s *Server) Start() error {
|
||||||
|
|
||||||
s.worker = NewWorker(temporalClient, s.cfg, s.logger, sqliteDb, kvStore)
|
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 {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to create templates")
|
return errors.Wrap(err, "failed to create templates")
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
func NewServer(l *slog.Logger, cfg *config.Config, tokenKeyProvider authorization.TokenKeyProvider) (t.Server, error) {
|
func NewServer(l *slog.Logger, cfg *config.Config, tokenKeyProvider authorization.TokenKeyProvider) (t.Server, error) {
|
||||||
logger := slogLogger{
|
logger := slogLogger{
|
||||||
log: l,
|
log: l,
|
||||||
level: slog.LevelDebug,
|
level: slog.LevelInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlConfig := cfg.Persistence.DataStores[PersistenceStoreName].SQL
|
sqlConfig := cfg.Persistence.DataStores[PersistenceStoreName].SQL
|
||||||
|
|
|
@ -39,7 +39,9 @@
|
||||||
{{ template "main" . }}
|
{{ template "main" . }}
|
||||||
<div class="container mx-auto">
|
<div class="container mx-auto">
|
||||||
<footer class="text-center text-gray-600 text-xs mt-8 mb-4">
|
<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
|
<a
|
||||||
class="hover:underline"
|
class="hover:underline"
|
||||||
|
|
|
@ -23,7 +23,7 @@ type Templates struct {
|
||||||
templates map[string]*template.Template
|
templates map[string]*template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
func load(files ...string) *template.Template {
|
func load(version string, files ...string) *template.Template {
|
||||||
files = append(files, base)
|
files = append(files, base)
|
||||||
|
|
||||||
t := template.New("default").Funcs(
|
t := template.New("default").Funcs(
|
||||||
|
@ -44,17 +44,20 @@ func load(files ...string) *template.Template {
|
||||||
"Now": time.Now,
|
"Now": time.Now,
|
||||||
"ScriptUnescapeString": script.UnescapeString,
|
"ScriptUnescapeString": script.UnescapeString,
|
||||||
"ScriptEscapeString": script.EscapeString,
|
"ScriptEscapeString": script.EscapeString,
|
||||||
|
"Version": func() string {
|
||||||
|
return version
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return template.Must(t.ParseFS(templates, files...))
|
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")
|
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{
|
t := Templates{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
templates: map[string]*template.Template{},
|
templates: map[string]*template.Template{},
|
||||||
|
@ -69,9 +72,9 @@ func NewTemplates(logger *slog.Logger) (*Templates, error) {
|
||||||
pathWithoutPrefix := strings.TrimPrefix(path, "pages/")
|
pathWithoutPrefix := strings.TrimPrefix(path, "pages/")
|
||||||
|
|
||||||
if strings.Contains(path, "settings") {
|
if strings.Contains(path, "settings") {
|
||||||
t.templates[pathWithoutPrefix] = loadSettings(path)
|
t.templates[pathWithoutPrefix] = loadSettings(version, path)
|
||||||
} else {
|
} else {
|
||||||
t.templates[pathWithoutPrefix] = load(path)
|
t.templates[pathWithoutPrefix] = load(version, path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue