Files
status/api/suite_status.go
zeekayandHanzo Dev 78ab4f2f83 Declare operations on the group that serves them, and build on Go 1.27
zip's registration is a verb method on the group, so a route that is not a typed
operation says which method it answers with. The security package's own
two-method router goes with it: it existed so both the app and a sub-router could
satisfy one name, and restating a routing surface is what let the two disagree —
the methods it named no longer exist. The app spells itself as a group, which
registers at exactly the paths it did.

The toolchain and the pin move together, because below zip v1.36.50 the JSON
encoder was selected on a build tag: a repo whose go directive rises first writes
a wire that is neither the old release's nor the new one's until the pin catches
up.

metrics_test.go still does not compile, before and after: it compares a metric
registry against a gatherer from a different metrics library, so the two Gather
signatures disagree. That is its own change.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-17 09:58:39 -07:00

60 lines
1.7 KiB
Go

package api
import (
"fmt"
"github.com/zap-proto/zip"
"hanzo.ai/status/config"
"hanzo.ai/status/config/suite"
"hanzo.ai/status/storage/store"
"hanzo.ai/status/storage/store/common/paging"
)
// SuiteStatuses handles requests to retrieve all suite statuses
func SuiteStatuses(cfg *config.Config) zip.Handler {
return func(c *zip.Ctx) error {
page, pageSize := extractPageAndPageSizeFromRequest(c, 100)
params := paging.NewSuiteStatusParams().WithPagination(page, pageSize)
suiteStatuses, err := store.Get().GetAllSuiteStatuses(params)
if err != nil {
return writeJSON(c, 500, map[string]any{
"error": fmt.Sprintf("Failed to retrieve suite statuses: %v", err),
})
}
// If no statuses exist yet, create empty ones from config
if len(suiteStatuses) == 0 {
for _, s := range cfg.Suites {
if s.IsEnabled() {
suiteStatuses = append(suiteStatuses, suite.NewStatus(s))
}
}
}
return writeJSON(c, 200, suiteStatuses)
}
}
// SuiteStatus handles requests to retrieve a single suite's status
func SuiteStatus(cfg *config.Config) zip.Handler {
return func(c *zip.Ctx) error {
page, pageSize := extractPageAndPageSizeFromRequest(c, 100)
key := c.Param("key")
params := paging.NewSuiteStatusParams().WithPagination(page, pageSize)
status, err := store.Get().GetSuiteStatusByKey(key, params)
if err != nil || status == nil {
// Try to find the suite in config
for _, s := range cfg.Suites {
if s.Key() == key {
status = suite.NewStatus(s)
break
}
}
if status == nil {
return writeJSON(c, 404, map[string]any{
"error": fmt.Sprintf("Suite with key '%s' not found", key),
})
}
}
return writeJSON(c, 200, status)
}
}