func CheckStatus() map[string]string
CheckStatus returns a map with all the current health check errors from the default registry.
func Handler(handler http.Handler) http.Handler
Handler returns a handler that will return 503 response code if the health checks have failed. If everything is okay with the health checks, the handler will pass through to the provided handler. Use this handler to disable a web application when the health checks fail.
func Register(name string, check Checker)
Register associates the checker with the provided name in the default registry.
func RegisterFunc(name string, check func() error)
RegisterFunc allows the convenience of registering a checker in the default registry directly from an arbitrary func() error.
func RegisterPeriodicFunc(name string, period time.Duration, check CheckFunc)
RegisterPeriodicFunc allows the convenience of registering a PeriodicChecker in the default registry from an arbitrary func() error.
func RegisterPeriodicThresholdFunc(name string, period time.Duration, threshold int, check CheckFunc)
RegisterPeriodicThresholdFunc allows the convenience of registering a PeriodicChecker in the default registry from an arbitrary func() error.
func StatusHandler(w http.ResponseWriter, r *http.Request)
StatusHandler returns a JSON blob with all the currently registered Health Checks and their corresponding status. Returns 503 if any Error status exists, 200 otherwise
CheckFunc is a convenience type to create functions that implement the Checker interface
type CheckFunc func() error
func (cf CheckFunc) Check() error
Check Implements the Checker interface to allow for any func() error method to be passed as a Checker
Checker is the interface for a Health Checker
type Checker interface { // Check returns nil if the service is okay. Check() error }
func PeriodicChecker(check Checker, period time.Duration) Checker
PeriodicChecker wraps an updater to provide a periodic checker
func PeriodicThresholdChecker(check Checker, period time.Duration, threshold int) Checker
PeriodicThresholdChecker wraps an updater to provide a periodic checker that uses a threshold before it changes status
A Registry is a collection of checks. Most applications will use the global registry defined in DefaultRegistry. However, unit tests may need to create separate registries to isolate themselves from other tests.
type Registry struct {
// contains filtered or unexported fields
}
DefaultRegistry is the default registry where checks are registered. It is the registry used by the HTTP handler.
var DefaultRegistry *Registry
func NewRegistry() *Registry
NewRegistry creates a new registry. This isn't necessary for normal use of the package, but may be useful for unit tests so individual tests have their own set of checks.
func (registry *Registry) CheckStatus() map[string]string
CheckStatus returns a map with all the current health check errors
func (registry *Registry) Register(name string, check Checker)
Register associates the checker with the provided name.
func (registry *Registry) RegisterFunc(name string, check func() error)
RegisterFunc allows the convenience of registering a checker directly from an arbitrary func() error.
func (registry *Registry) RegisterPeriodicFunc(name string, period time.Duration, check CheckFunc)
RegisterPeriodicFunc allows the convenience of registering a PeriodicChecker from an arbitrary func() error.
func (registry *Registry) RegisterPeriodicThresholdFunc(name string, period time.Duration, threshold int, check CheckFunc)
RegisterPeriodicThresholdFunc allows the convenience of registering a PeriodicChecker from an arbitrary func() error.
Updater implements a health check that is explicitly set.
type Updater interface { Checker // Update updates the current status of the health check. Update(status error) }
func NewStatusUpdater() Updater
NewStatusUpdater returns a new updater
func NewThresholdStatusUpdater(t int) Updater
NewThresholdStatusUpdater returns a new thresholdUpdater