Files
nmon/internal/api/meta.go
jleung f85c3ef781
Some checks failed
ci / lint (push) Has been cancelled
ci / test (ubuntu-24.04-arm) (push) Has been cancelled
ci / test (ubuntu-latest) (push) Has been cancelled
ci / postgres (push) Has been cancelled
ci / openapi (push) Has been cancelled
M3: Go API per UI contract, embedded UI, openapi compat check, nmon-devtools, live gate + screenshots; M4 WP1 reachability and dependency suppression
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
2026-10-22 20:34:14 +00:00

42 lines
1.3 KiB
Go

package api
import (
"context"
"net/http"
"time"
"github.com/danielgtaylor/huma/v2"
"github.com/v10networks/nmon/internal/buildinfo"
)
// Retention reports how long each store keeps data, as Go duration strings such as "720h0m0s".
type Retention struct {
Hot string `json:"hot" example:"720h0m0s"`
FiveMinute string `json:"fiveminute"`
Long string `json:"long"`
}
// Meta is what the UI footer and range picker need to know about this server.
type Meta struct {
Version string `json:"version" doc:"Release version stamped at build time; dev for an unstamped build."`
Build string `json:"build" doc:"Commit the binary was built from."`
Retention Retention `json:"retention"`
Now time.Time `json:"now" doc:"Server time, UTC."`
}
func (s *server) registerMeta(api huma.API) {
huma.Register(api, huma.Operation{
OperationID: "get-meta", Method: http.MethodGet, Path: "/api/v1/meta", Tags: []string{"meta"},
Summary: "Version, build, retention and server time",
}, func(context.Context, *struct{}) (*struct{ Body Meta }, error) {
v, b := buildinfo.Info()
return &struct{ Body Meta }{Meta{
Version: v, Build: b, Now: s.Clock.Now().UTC(),
Retention: Retention{
Hot: s.HotRetention.String(), FiveMinute: s.FiveMinuteRetention.String(), Long: s.LongRetention.String(),
},
}}, nil
})
}