aboutsummaryrefslogtreecommitdiff
path: root/internal/server/server.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-20 17:42:26 -0800
committerFuwn <[email protected]>2026-01-20 17:42:26 -0800
commit62ab70a607ae0fa1611495c0fb441db5c780704f (patch)
tree4e7fe1898fc3ad77820d2a116a4b2eb8922c9aa6 /internal/server/server.go
parentfeat: Add POST /api/reload endpoint for config reload (diff)
downloadkaze-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/server.go')
-rw-r--r--internal/server/server.go44
1 files changed, 44 insertions, 0 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 == "" {