From 62ab70a607ae0fa1611495c0fb441db5c780704f Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 20 Jan 2026 17:42:26 -0800 Subject: feat: Add version tooltip to 'Powered by Kaze' footer - Add VersionInfo struct to server - Add SetVersion() method called from main.go - Display version, commit, and build date in hoverable tooltip - Tooltip uses same style as other tooltips in the UI --- cmd/kaze/main.go | 4 +++- internal/server/server.go | 44 ++++++++++++++++++++++++++++++++++++ internal/server/templates/index.html | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/cmd/kaze/main.go b/cmd/kaze/main.go index f4f61ac..f9e9cd4 100644 --- a/cmd/kaze/main.go +++ b/cmd/kaze/main.go @@ -90,6 +90,7 @@ func main() { logger.Error("failed to initialize server", "error", err) os.Exit(1) } + srv.SetVersion(version, commit, date) // Setup graceful shutdown ctx, cancel := context.WithCancel(context.Background()) @@ -188,8 +189,9 @@ func main() { return fmt.Errorf("failed to create new server: %w", err) } - // Replace server and set reload func on new server + // Replace server and set reload func and version on new server srv = newSrv + srv.SetVersion(version, commit, date) srv.SetReloadFunc(reloadConfig) // Start new server diff --git a/internal/server/server.go b/internal/server/server.go index ab9ff24..6b7fbfb 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -31,6 +31,13 @@ var staticFS embed.FS // ReloadFunc is a callback function for reloading configuration type ReloadFunc func() error +// VersionInfo contains build version information +type VersionInfo struct { + Version string + Commit string + Date string +} + // Server handles HTTP requests for the status page type Server struct { config *config.Config @@ -40,6 +47,7 @@ type Server struct { server *http.Server templates *template.Template reloadConfig ReloadFunc + version VersionInfo } // New creates a new HTTP server @@ -225,6 +233,7 @@ type PageData struct { Scale float64 // UI scale factor (0.5-2.0) RefreshMode string // page or api RefreshInterval int // seconds + VersionTooltip string // JSON data for version tooltip } // StatusCounts holds monitor status counts for display @@ -326,6 +335,7 @@ func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) { Scale: s.config.Display.Scale, RefreshMode: s.config.Display.RefreshMode, RefreshInterval: s.config.Display.RefreshInterval, + VersionTooltip: s.formatVersionTooltip(), } overallUp := true @@ -1023,6 +1033,15 @@ func (s *Server) SetReloadFunc(fn ReloadFunc) { s.reloadConfig = fn } +// SetVersion sets the version information for display +func (s *Server) SetVersion(version, commit, date string) { + s.version = VersionInfo{ + Version: version, + Commit: commit, + Date: date, + } +} + // handleAPIReload triggers a configuration reload (always requires authentication) func (s *Server) handleAPIReload(w http.ResponseWriter, r *http.Request) { if s.reloadConfig == nil { @@ -1474,6 +1493,31 @@ func formatUptimeTooltip(uptimePercent float64, totalChecks int64, lastFailure * return string(b) } +// formatVersionTooltip creates JSON data for version tooltip +func (s *Server) formatVersionTooltip() string { + rows := []map[string]string{ + {"label": "Version", "value": s.version.Version, "class": ""}, + {"label": "Commit", "value": s.version.Commit, "class": ""}, + } + + // Parse and format build date if available + if s.version.Date != "" && s.version.Date != "unknown" { + if t, err := time.Parse(time.RFC3339, s.version.Date); err == nil { + rows = append(rows, map[string]string{"label": "Built", "value": t.Format("Jan 2, 2006 15:04"), "class": ""}) + } else { + rows = append(rows, map[string]string{"label": "Built", "value": s.version.Date, "class": ""}) + } + } + + data := map[string]interface{}{ + "header": "Kaze", + "rows": rows, + } + + b, _ := json.Marshal(data) + return string(b) +} + // simplifyErrorMessage simplifies error messages for display func simplifyErrorMessage(err string) string { if err == "" { diff --git a/internal/server/templates/index.html b/internal/server/templates/index.html index 6471e53..35f08c1 100644 --- a/internal/server/templates/index.html +++ b/internal/server/templates/index.html @@ -187,7 +187,7 @@ -- cgit v1.2.3