v1.0.0
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.
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
}
Releases
2
Release v1.0.0
Latest
Languages
Go
100%