feat(statuspage): serve public status pages from api snapshots
Pages render without JavaScript, are matched by verified custom domain or by slug, and stay available from a stale snapshot for ten minutes if the API is unreachable. Snapshots contain no targets or error details. Refs #21, #22 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
d820547e8c
commit
2b72715a9d
8 files changed
+1017
No files matched your search
@@ -0,0 +1,83 @@
|
||||
package agentapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Page states, from best to worst.
|
||||
const (
|
||||
PageOperational = "operational"
|
||||
PageDegraded = "degraded"
|
||||
PageOutage = "outage"
|
||||
PageUnknown = "unknown"
|
||||
)
|
||||
|
||||
// Theme customizes a page.
|
||||
type Theme struct {
|
||||
// Accent is a #rrggbb color for headings and links.
|
||||
Accent string `json:"accent,omitempty"`
|
||||
LogoURL string `json:"logo_url,omitempty"`
|
||||
// CSS is appended to the page's styles.
|
||||
CSS string `json:"css,omitempty"`
|
||||
}
|
||||
|
||||
// Day is one bar of a component's 90-day history. Uptime is -1 without data.
|
||||
type Day struct {
|
||||
Date string `json:"date"`
|
||||
Uptime float64 `json:"uptime"`
|
||||
}
|
||||
|
||||
// Component is one monitor as the public sees it. Targets, check details
|
||||
// and error messages stay private.
|
||||
type Component struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Uptime float64 `json:"uptime"`
|
||||
Days []Day `json:"days"`
|
||||
}
|
||||
|
||||
// Section groups components under a heading; the first may be unnamed.
|
||||
type Section struct {
|
||||
Name string `json:"name"`
|
||||
Components []Component `json:"components"`
|
||||
}
|
||||
|
||||
// PageIncident is an incident of a listed component.
|
||||
type PageIncident struct {
|
||||
Component string `json:"component"`
|
||||
StartedAt time.Time `json:"started_at"`
|
||||
ResolvedAt *time.Time `json:"resolved_at,omitempty"`
|
||||
}
|
||||
|
||||
// PageSnapshot is everything needed to render a status page.
|
||||
type PageSnapshot struct {
|
||||
Slug string `json:"slug"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Theme Theme `json:"theme"`
|
||||
Status string `json:"status"`
|
||||
Sections []Section `json:"sections"`
|
||||
Incidents []PageIncident `json:"incidents"`
|
||||
GeneratedAt time.Time `json:"generated_at"`
|
||||
}
|
||||
|
||||
// ErrNotFound means no published page matches.
|
||||
var ErrNotFound = errors.New("agentapi: not found")
|
||||
|
||||
// Page fetches the published page for a custom domain host, or for slug if
|
||||
// host is empty.
|
||||
func (c *Client) Page(ctx context.Context, host, slug string) (PageSnapshot, error) {
|
||||
q := url.Values{}
|
||||
if host != "" {
|
||||
q.Set("host", host)
|
||||
} else {
|
||||
q.Set("slug", slug)
|
||||
}
|
||||
var p PageSnapshot
|
||||
err := c.do(ctx, http.MethodGet, "/pages?"+q.Encode(), nil, &p)
|
||||
return p, err
|
||||
}
|
||||
Reference in new issue
Block a user