-
Notifications
You must be signed in to change notification settings - Fork 0
/
govhealth.go
63 lines (55 loc) · 1.29 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package governor
import (
"github.com/labstack/echo/v4"
"net/http"
"strconv"
"time"
)
type (
errRes struct {
Message string `json:"message"`
}
healthRes struct {
Time int64 `json:"time"`
Errs []errRes `json:"errs"`
}
)
func (s *Server) initHealth(r *echo.Group) {
r.GET("/check", func(c echo.Context) error {
return c.String(http.StatusOK, strconv.FormatInt(time.Now().Round(0).Unix(), 10))
})
r.GET("/report", func(c echo.Context) error {
t := time.Now().Round(0).Unix()
if errs := s.checkHealthServices(); len(errs) > 0 {
errReslist := []errRes{}
for _, i := range errs {
errReslist = append(errReslist, errRes{
Message: i.Error(),
})
}
return c.JSON(http.StatusInternalServerError, &healthRes{
Time: t,
Errs: errReslist,
})
}
return c.JSON(http.StatusOK, &healthRes{
Time: t,
Errs: nil,
})
})
if s.config.IsDebug() {
r.GET("/version", func(c echo.Context) error {
return c.String(http.StatusOK, s.config.Version)
})
r.GET("/ping", func(c echo.Context) error {
s.logger.Debug("Ping", map[string]string{
"request": "ping",
"response": "pong",
})
return c.String(http.StatusOK, "Pong")
})
r.GET("/error", func(c echo.Context) error {
return NewError("Test error", http.StatusBadRequest, nil)
})
}
}