Documentation
¶
Overview ¶
Package health implements liveness and readiness checks for sqi-server.
Concepts ¶
A Checker represents one dependency that must be reachable for the server to be considered ready. Components register themselves via Registry.Register during startup; later tasks wire in real implementations:
- SQLite store checker - NATS JetStream checker
Endpoints ¶
Registry.LivenessHandler → GET /healthz
Always returns HTTP 200 with {"status":"ok"}. It performs no dependency checks; its only purpose is to prove the process is alive and the HTTP event loop is responding. An orchestrator that receives a non-200 here (or a timeout) will restart the process.
Registry.ReadinessHandler → GET /readyz
Runs all registered checkers concurrently under a five-second deadline. Returns HTTP 200 with {"status":"ok","checks":{…}} when every checker passes, or HTTP 503 with {"status":"degraded","checks":{…}} when any checker fails. If no checkers are registered the server is considered ready immediately — components opt in to readiness gating by calling Register.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Checker ¶
Checker is implemented by any component that wants to gate server readiness. Check must return nil when the component is healthy and a descriptive, human-readable error when it is not. Implementations must honor context cancellation and return promptly when ctx is done.
type CheckerFunc ¶
CheckerFunc is a function that implements Checker. It allows an inline closure to be registered without defining a named type.
reg.Register("sqlite", health.CheckerFunc(func(ctx context.Context) error {
return db.PingContext(ctx)
}))
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds a set of named [Checker]s consulted by Registry.ReadinessHandler. It is safe for concurrent use; components may call Registry.Register from any goroutine, including during server startup.
func (*Registry) LivenessHandler ¶
LivenessHandler returns an http.Handler for GET /healthz.
It always responds HTTP 200 with {"status":"ok"} and performs no dependency checks. Use this as a process-alive probe — if the handler stops responding the process should be restarted.
func (*Registry) ReadinessHandler ¶
ReadinessHandler returns an http.Handler for GET /readyz.
It runs all registered checkers concurrently under a [checkTimeout] deadline derived from the incoming request context. The response body always includes a per-checker breakdown regardless of overall status.
HTTP 200 {"status":"ok","checks":{…}} — all checkers passed. HTTP 503 {"status":"degraded","checks":{…}} — one or more checkers failed.