-
Notifications
You must be signed in to change notification settings - Fork 20.8k
/
Copy pathhealthcheck.go
35 lines (29 loc) · 931 Bytes
/
healthcheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package metrics
// NewHealthcheck constructs a new Healthcheck which will use the given
// function to update its status.
func NewHealthcheck(f func(*Healthcheck)) *Healthcheck {
return &Healthcheck{nil, f}
}
// Healthcheck is the standard implementation of a Healthcheck and
// stores the status and a function to call to update the status.
type Healthcheck struct {
err error
f func(*Healthcheck)
}
// Check runs the healthcheck function to update the healthcheck's status.
func (h *Healthcheck) Check() {
h.f(h)
}
// Error returns the healthcheck's status, which will be nil if it is healthy.
func (h *Healthcheck) Error() error {
return h.err
}
// Healthy marks the healthcheck as healthy.
func (h *Healthcheck) Healthy() {
h.err = nil
}
// Unhealthy marks the healthcheck as unhealthy. The error is stored and
// may be retrieved by the Error method.
func (h *Healthcheck) Unhealthy(err error) {
h.err = err
}