health

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package health provides health check functionality for the application.

Index

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

func NewHandler(registry *Registry) *Handler

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

func (h *Handler) RegisterRoutes(mux *http.ServeMux)

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

func NewRegistry(version string) *Registry

NewRegistry creates a new health check registry.

func (*Registry) Checkers

func (r *Registry) Checkers() []Checker

Checkers returns a copy of the registered checkers.

func (*Registry) Health

func (r *Registry) Health(ctx context.Context) Response

Health returns a full health check with all registered checkers.

func (*Registry) Liveness

func (r *Registry) Liveness(ctx context.Context) Response

Liveness returns a liveness check response. Liveness checks only fail if the process is broken (e.g., deadlock).

func (*Registry) Readiness

func (r *Registry) Readiness(ctx context.Context) Response

Readiness checks if the application is ready to serve traffic. It runs all critical health checks concurrently.

func (*Registry) Register

func (r *Registry) Register(checker Checker)

Register adds a health checker to the registry.

func (*Registry) StartTime

func (r *Registry) StartTime() time.Time

StartTime returns when the registry was created.

func (*Registry) Version

func (r *Registry) Version() string

Version returns the version string.

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 Severity

type Severity string

Severity represents the severity level of a health check.

const (
	// SeverityCritical affects readiness (affects /ready endpoint).
	SeverityCritical Severity = "critical"
	// SeverityWarning is logged but doesn't affect readiness.
	SeverityWarning Severity = "warning"
)

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"
)

Directories

Path Synopsis
Package checks provides built-in health checkers.
Package checks provides built-in health checkers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL