2020-06-15 10:04:08 +00:00
|
|
|
package health
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Status uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
HEALTHY Status = 0
|
|
|
|
INITIALIZING Status = 1
|
|
|
|
UNHEALTHY Status = 2
|
|
|
|
UNKNOWN Status = 3
|
|
|
|
)
|
|
|
|
|
|
|
|
type CheckResult struct {
|
|
|
|
Status Status
|
|
|
|
Message string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Result struct {
|
|
|
|
Status Status
|
|
|
|
Components map[string]CheckResult
|
|
|
|
}
|
|
|
|
|
|
|
|
type Check func() CheckResult
|
|
|
|
|
|
|
|
var (
|
2020-12-26 13:11:49 +00:00
|
|
|
ErrCheckForComponentAlreadyRegistered = errors.New("a check for the requested component is already registered")
|
2020-06-15 10:04:08 +00:00
|
|
|
)
|
|
|
|
|
2020-12-26 13:11:49 +00:00
|
|
|
func New() Checker {
|
|
|
|
return &checker{
|
2020-06-15 10:04:08 +00:00
|
|
|
componentChecks: map[string]Check{},
|
|
|
|
}
|
|
|
|
}
|