-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
health.go
56 lines (47 loc) · 1.03 KB
/
health.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"github.com/nelkinda/health-go"
"net/http"
"time"
)
type healthCheck struct {
mail, captcha error
}
func (h *healthCheck) HealthChecks() map[string][]health.Checks {
now := time.Now().UTC().Format(time.RFC3339Nano)
errorCheck := func(err error) health.Checks {
if err == nil {
return health.Checks{
ComponentType: "component",
Status: health.Pass,
Time: now,
}
} else {
return health.Checks{
ComponentType: "component",
Status: health.Fail,
Time: now,
Output: err.Error(),
}
}
}
return map[string][]health.Checks{
"mail": {errorCheck(h.mail)},
"captcha": {errorCheck(h.captcha)},
}
}
func (*healthCheck) AuthorizeHealth(*http.Request) bool {
return true
}
func (h *healthCheck) recordMailFailure(err error) {
h.mail = err
}
func (h *healthCheck) recordMailSuccess() {
h.mail = nil
}
func (h *healthCheck) recordCaptchaError(err error) {
h.captcha = err
}
func (h *healthCheck) recordCaptchaSuccess() {
h.captcha = nil
}