Rene Nochebuena 8d6930b087 feat(health)!: promote to v1.0.0 — configurable check timeout via NewHandlerWithConfig
Add Config struct and NewHandlerWithConfig(logger, cfg, checks...) constructor.
Config.CheckTimeout sets the per-request deadline for all health checks; zero
value defaults to 5 seconds. NewHandler remains unchanged as a backward-compatible
wrapper. API committed as stable.
2026-05-11 19:05:27 -06:00

health

Stdlib http.Handler for service health checks. Runs all checks concurrently and returns a JSON summary.

Install

go get code.nochebuena.dev/go/health

Usage

handler := health.NewHandler(logger, db, cache, queue)
r.Get("/health", handler)

Response

{
  "status": "UP",
  "components": {
    "db":    {"status": "UP",   "latency": "1.2ms"},
    "cache": {"status": "DOWN", "latency": "5ms", "error": "connection refused"}
  }
}
Overall status HTTP code Condition
UP 200 All checks pass
DEGRADED 200 One or more LevelDegraded checks fail; no critical failures
DOWN 503 One or more LevelCritical checks fail

Implementing Checkable

func (d *DB) HealthCheck(ctx context.Context) error { return d.pool.PingContext(ctx) }
func (d *DB) Name() string                          { return "postgres" }
func (d *DB) Priority() health.Level                { return health.LevelCritical }

Logger

health.Logger is a duck-typed interface satisfied by logz.Logger without importing it.

type Logger interface {
    Debug(msg string, args ...any)
    Info(msg string, args ...any)
    Warn(msg string, args ...any)
    Error(msg string, err error, args ...any)
    WithContext(ctx context.Context) Logger
}
Description
Three-phase application lifecycle manager with graceful shutdown and signal handling.
Readme MIT 50 KiB
2026-05-11 19:06:12 -06:00
Languages
Go 100%