Documentation
¶
Overview ¶
Package health provides health check functionality for the application.
Index ¶
- type CheckResult
- type Checker
- type CheckerFunc
- type Handler
- type LiveResponse
- type ReadyResponse
- type Registry
- func (r *Registry) Checkers() []Checker
- func (r *Registry) Health(ctx context.Context) Response
- func (r *Registry) Liveness(ctx context.Context) Response
- func (r *Registry) Readiness(ctx context.Context) Response
- func (r *Registry) Register(checker Checker)
- func (r *Registry) StartTime() time.Time
- func (r *Registry) Version() string
- type Response
- type Severity
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckResult ¶
type CheckResult struct {
Status Status `json:"status"`
Message string `json:"message,omitempty"`
Duration time.Duration `json:"duration,omitempty"`
Details map[string]any `json:"details,omitempty"`
}
CheckResult represents the result of an individual health check.
type Checker ¶
type Checker interface {
// Name returns the name of the health check.
Name() string
// Check performs the health check and returns the result.
Check(ctx context.Context) CheckResult
// Severity returns the severity level of this check.
Severity() Severity
}
Checker is the interface that health checks must implement.
type CheckerFunc ¶
type CheckerFunc func(ctx context.Context) CheckResult
CheckerFunc is a function adapter for simple health checks.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler provides HTTP handlers for health check endpoints.
func NewHandler ¶
NewHandler creates a new health check handler.
func (*Handler) HealthHandler ¶
func (h *Handler) HealthHandler(w http.ResponseWriter, r *http.Request)
HealthHandler handles GET /health endpoint. Returns overall health status with all check details.
func (*Handler) LivenessHandler ¶
func (h *Handler) LivenessHandler(w http.ResponseWriter, r *http.Request)
LivenessHandler handles GET /health/live endpoint. Used for Kubernetes liveness probes. Returns 200 unless the process is broken.
func (*Handler) ReadinessHandler ¶
func (h *Handler) ReadinessHandler(w http.ResponseWriter, r *http.Request)
ReadinessHandler handles GET /health/ready endpoint. Used for Kubernetes readiness probes. Returns 503 if critical dependencies are unavailable.
func (*Handler) RegisterRoutes ¶
RegisterRoutes registers health check routes on an http.ServeMux.
type LiveResponse ¶
type LiveResponse struct {
Status string `json:"status"`
}
LiveResponse represents a liveness check response.
type ReadyResponse ¶
type ReadyResponse struct {
Status string `json:"status"`
Checks map[string]string `json:"checks,omitempty"`
}
ReadyResponse represents a readiness check response.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages health checkers and executes checks.
func NewRegistry ¶
NewRegistry creates a new health check registry.
func (*Registry) Liveness ¶
Liveness returns a liveness check response. Liveness checks only fail if the process is broken (e.g., deadlock).
func (*Registry) Readiness ¶
Readiness checks if the application is ready to serve traffic. It runs all critical health checks concurrently.
type Response ¶
type Response struct {
Status Status `json:"status"`
Timestamp time.Time `json:"timestamp"`
Version string `json:"version,omitempty"`
Uptime string `json:"uptime,omitempty"`
Checks map[string]CheckResult `json:"checks,omitempty"`
}
Response represents a health check response.
type Status ¶
type Status string
Status represents the health status of a component.
const ( // StatusHealthy indicates the component is functioning normally. StatusHealthy Status = "healthy" // StatusUnhealthy indicates the component is not functioning. StatusUnhealthy Status = "unhealthy" // StatusDegraded indicates the component is functioning but with issues. StatusDegraded Status = "degraded" )