Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
42 lines
1.3 KiB
Go
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
|
|
})
|
|
}
|