feat: include app version in sidebar footer
All checks were successful
Deploy / build-and-deploy (push) Successful in 1m0s
All checks were successful
Deploy / build-and-deploy (push) Successful in 1m0s
This commit is contained in:
parent
720d043dee
commit
b47e48b882
7 changed files with 46 additions and 7 deletions
|
|
@ -19,7 +19,7 @@ import (
|
|||
var version = "dev"
|
||||
|
||||
func main() {
|
||||
cfg := config.Load()
|
||||
cfg := config.Load(version)
|
||||
|
||||
a, err := app.New(cfg)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -33,9 +33,11 @@ type Config struct {
|
|||
MailerEmailFrom string
|
||||
|
||||
SupportEmail string
|
||||
|
||||
Version string
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
func Load(version string) *Config {
|
||||
|
||||
if err := godotenv.Load(); err != nil {
|
||||
slog.Info("no .env file found, using environment variables")
|
||||
|
|
@ -65,6 +67,8 @@ func Load() *Config {
|
|||
MailerEmailFrom: envString("MAILER_EMAIL_FROM", ""),
|
||||
|
||||
SupportEmail: envString("SUPPORT_EMAIL", ""),
|
||||
|
||||
Version: version,
|
||||
}
|
||||
|
||||
return cfg
|
||||
|
|
@ -87,6 +91,8 @@ func (c *Config) Sanitized() *Config {
|
|||
|
||||
MailerEmailFrom: c.MailerEmailFrom,
|
||||
SupportEmail: c.SupportEmail,
|
||||
|
||||
Version: c.Version,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ const (
|
|||
URLPathKey string = "url_path"
|
||||
ConfigKey string = "config"
|
||||
CSRFTokenKey string = "csrf_token"
|
||||
AppVersionKey string = "app_version"
|
||||
)
|
||||
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
16
internal/middleware/app_version.go
Normal file
16
internal/middleware/app_version.go
Normal 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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -181,6 +181,7 @@ func SetupRoutes(a *app.App) http.Handler {
|
|||
// Global middlewares
|
||||
handler := middleware.Chain(
|
||||
mux,
|
||||
middleware.AppVersion(a.Cfg.Version),
|
||||
middleware.Config(a.Cfg),
|
||||
middleware.RequestLogging,
|
||||
middleware.NoCacheDynamic,
|
||||
|
|
|
|||
|
|
@ -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.Menu() {
|
||||
@sidebar.MenuItem() {
|
||||
|
|
|
|||
|
|
@ -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.Menu() {
|
||||
@sidebar.MenuItem() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue