-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgovhealth.go
42 lines (36 loc) · 833 Bytes
/
govhealth.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
package governor
import (
"net/http"
"xorkevin.dev/klog"
)
type (
healthVersionRes struct {
Version string `json:"version"`
}
)
func (s *Server) initHealth(r Router) {
m := NewMethodRouter(r)
m.GetCtx("/live", func(c *Context) {
c.WriteStatus(http.StatusOK)
})
m.GetCtx("/ready", func(c *Context) {
errs := s.checkHealthServices(c.Ctx())
status := http.StatusOK
if len(errs) > 0 {
status = http.StatusInternalServerError
errstrs := make([]string, 0, len(errs))
for _, i := range errs {
errstrs = append(errstrs, i.Error())
}
s.log.Error(c.Ctx(), "Failed readiness check",
klog.AAny("errors", errstrs),
)
}
c.WriteStatus(status)
})
m.GetCtx("/version", func(c *Context) {
c.WriteJSON(http.StatusOK, healthVersionRes{
Version: s.settings.config.Version.String(),
})
})
}