health
API
health
packageAPI reference for the health
package.
Imports
(3)
T
type
Status
Status represents the health status of a component.
pkg/health/health.go:10-10
type Status int
S
struct
Report
Report contains the result of a health check.
pkg/health/health.go:36-40
type Report struct
Fields
| Name | Type | Description |
|---|---|---|
| Status | Status | |
| Duration | time.Duration | |
| Details | map[string]any |
Uses
I
interface
Checker
Checker performs a health check and returns a Report.
pkg/health/health.go:43-45
type Checker interface
Methods
S
struct
Registry
Registry manages a set of named health Checkers.
pkg/health/health.go:48-51
type Registry struct
Methods
Register
Method
Register adds a named checker to the registry.
Parameters
name
string
c
Checker
func (*Registry) Register(name string, c Checker)
{
r.mu.Lock()
defer r.mu.Unlock()
r.checks[name] = c
}
CheckAll
Method
Parameters
ctx
context.Context
Returns
map[string]Report
func (*Registry) CheckAll(ctx context.Context) map[string]Report
{
r.mu.RLock()
names := make([]string, 0, len(r.checks))
for n := range r.checks {
names = append(names, n)
}
r.mu.RUnlock()
results := make(map[string]Report, len(names))
for _, name := range names {
r.mu.RLock()
checker := r.checks[name]
r.mu.RUnlock()
start := time.Now()
report := checker.Check(ctx)
report.Duration = time.Since(start)
results[name] = report
}
return results
}
Fields
| Name | Type | Description |
|---|---|---|
| mu | sync.RWMutex | |
| checks | map[string]Checker |
F
function
NewRegistry
NewRegistry creates a new health check Registry.
Returns
pkg/health/health.go:54-56
func NewRegistry() *Registry
{
return &Registry{checks: make(map[string]Checker)}
}