Documentation
¶
Overview ¶
Package server wires the HTTP surface: middleware, health probes, metrics, graceful shutdown, and a chi router that other packages mount routes onto.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
Addr string
ShutdownTimeout time.Duration
// APIKey, when non-empty, gates /metrics on the main port behind the same
// bearer token used by the /v1 routes. A dedicated MetricsAddr port is
// unauthenticated instead.
APIKey string
// MetricsAddr, when set and distinct from Addr, serves /metrics on its own
// unauthenticated listener instead of the main router — a port meant to stay
// in-cluster (keep it off any public route).
MetricsAddr string
// UIAddr, when set and distinct from Addr, serves the admin UI on its own
// listener instead of the main router (see MountUI). The shell embeds the
// API key, so isolating it keeps that key off the main port — expose UIAddr
// only on a trusted (LAN) gateway.
UIAddr string
}
Options configures the server without importing the config package.
type ReadinessFunc ¶
ReadinessFunc reports whether the service is ready to serve traffic. A nil error means ready; a non-nil error is surfaced on /readyz.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server owns the HTTP server and its router.
func New ¶
New builds a Server with base middleware, /healthz, /readyz and /metrics. Additional routes are mounted via Router before calling Run.
func (*Server) MountUI ¶ added in v0.5.10
MountUI arranges for the SPA handler to be served. When UIAddr is set and distinct from Addr, spa is served ONLY on that dedicated listener, which delegates requests matching an API route to the main router so the same-origin SPA can still call /v1 — keeping the token-embedding shell off the main port. Otherwise spa is mounted as a catch-all on the main router, serving it on the main port (single-listener default).
func (*Server) Run ¶
Run starts the HTTP server and blocks until ctx is cancelled, then performs a graceful shutdown bounded by the configured timeout.
func (*Server) SetReady ¶
func (s *Server) SetReady(fn ReadinessFunc)
SetReady installs the readiness check used by /readyz.