diff options
| author | Fuwn <[email protected]> | 2026-01-20 17:42:26 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-20 17:42:26 -0800 |
| commit | 62ab70a607ae0fa1611495c0fb441db5c780704f (patch) | |
| tree | 4e7fe1898fc3ad77820d2a116a4b2eb8922c9aa6 /internal/server | |
| parent | feat: Add POST /api/reload endpoint for config reload (diff) | |
| download | kaze-62ab70a607ae0fa1611495c0fb441db5c780704f.tar.xz kaze-62ab70a607ae0fa1611495c0fb441db5c780704f.zip | |
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
Diffstat (limited to 'internal/server')
| -rw-r--r-- | internal/server/server.go | 44 | ||||
| -rw-r--r-- | internal/server/templates/index.html | 2 |
2 files changed, 45 insertions, 1 deletions
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 @@ <footer class="mt-12 pt-6 border-t border-neutral-200 dark:border-neutral-800"> <div class="flex items-center justify-between text-xs text-neutral-500 dark:text-neutral-400"> <span data-tooltip='{{.LastUpdatedTooltip}}'{{if $.UseBrowserTimezone}} data-timestamp="{{$.LastUpdated.Format "2006-01-02T15:04:05Z07:00"}}" data-format="timeago"{{end}}>Updated {{timeAgo $.LastUpdated}}</span> - <span>Powered by <a href="https://github.com/Fuwn/kaze" class="hover:text-neutral-900 dark:hover:text-neutral-100">Kaze</a></span> + <span data-tooltip='{{.VersionTooltip}}'>Powered by <a href="https://github.com/Fuwn/kaze" class="hover:text-neutral-900 dark:hover:text-neutral-100">Kaze</a></span> </div> </footer> </div> |