feat: include app version in sidebar footer
All checks were successful
Deploy / build-and-deploy (push) Successful in 1m0s

This commit is contained in:
juancwu 2026-02-09 21:51:16 +00:00
commit b47e48b882
7 changed files with 46 additions and 7 deletions

View file

@ -19,7 +19,7 @@ import (
var version = "dev" var version = "dev"
func main() { func main() {
cfg := config.Load() cfg := config.Load(version)
a, err := app.New(cfg) a, err := app.New(cfg)
if err != nil { if err != nil {

View file

@ -33,9 +33,11 @@ type Config struct {
MailerEmailFrom string MailerEmailFrom string
SupportEmail string SupportEmail string
Version string
} }
func Load() *Config { func Load(version string) *Config {
if err := godotenv.Load(); err != nil { if err := godotenv.Load(); err != nil {
slog.Info("no .env file found, using environment variables") slog.Info("no .env file found, using environment variables")
@ -65,6 +67,8 @@ func Load() *Config {
MailerEmailFrom: envString("MAILER_EMAIL_FROM", ""), MailerEmailFrom: envString("MAILER_EMAIL_FROM", ""),
SupportEmail: envString("SUPPORT_EMAIL", ""), SupportEmail: envString("SUPPORT_EMAIL", ""),
Version: version,
} }
return cfg return cfg
@ -87,6 +91,8 @@ func (c *Config) Sanitized() *Config {
MailerEmailFrom: c.MailerEmailFrom, MailerEmailFrom: c.MailerEmailFrom,
SupportEmail: c.SupportEmail, SupportEmail: c.SupportEmail,
Version: c.Version,
} }
} }

View file

@ -8,11 +8,12 @@ import (
) )
const ( const (
UserKey string = "user" UserKey string = "user"
ProfileKey string = "profile" ProfileKey string = "profile"
URLPathKey string = "url_path" URLPathKey string = "url_path"
ConfigKey string = "config" ConfigKey string = "config"
CSRFTokenKey string = "csrf_token" CSRFTokenKey string = "csrf_token"
AppVersionKey string = "app_version"
) )
func User(ctx context.Context) *model.User { func User(ctx context.Context) *model.User {
@ -59,3 +60,12 @@ func CSRFToken(ctx context.Context) string {
func WithCSRFToken(ctx context.Context, token string) context.Context { func WithCSRFToken(ctx context.Context, token string) context.Context {
return context.WithValue(ctx, CSRFTokenKey, token) return context.WithValue(ctx, CSRFTokenKey, token)
} }
func AppVersion(ctx context.Context) string {
version, _ := ctx.Value(AppVersionKey).(string)
return version
}
func WithAppVersion(ctx context.Context, version string) context.Context {
return context.WithValue(ctx, AppVersionKey, version)
}

View file

@ -0,0 +1,16 @@
package middleware
import (
"net/http"
"git.juancwu.dev/juancwu/budgit/internal/ctxkeys"
)
func AppVersion(version string) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := ctxkeys.WithAppVersion(r.Context(), version)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
}

View file

@ -181,6 +181,7 @@ func SetupRoutes(a *app.App) http.Handler {
// Global middlewares // Global middlewares
handler := middleware.Chain( handler := middleware.Chain(
mux, mux,
middleware.AppVersion(a.Cfg.Version),
middleware.Config(a.Cfg), middleware.Config(a.Cfg),
middleware.RequestLogging, middleware.RequestLogging,
middleware.NoCacheDynamic, middleware.NoCacheDynamic,

View file

@ -68,6 +68,9 @@ templ App(title string) {
} }
} }
} }
<div class="px-2 py-1">
<span class="text-xs text-muted-foreground">App version: v{ ctxkeys.AppVersion(ctx) }</span>
</div>
@sidebar.Separator() @sidebar.Separator()
@sidebar.Menu() { @sidebar.Menu() {
@sidebar.MenuItem() { @sidebar.MenuItem() {

View file

@ -105,6 +105,9 @@ templ Space(title string, space *model.Space) {
} }
} }
} }
<div class="px-2 py-1">
<span class="text-xs text-muted-foreground">App version: v{ ctxkeys.AppVersion(ctx) }</span>
</div>
@sidebar.Separator() @sidebar.Separator()
@sidebar.Menu() { @sidebar.Menu() {
@sidebar.MenuItem() { @sidebar.MenuItem() {