-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealthcheck.go
40 lines (35 loc) · 1.12 KB
/
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
36
37
38
39
40
package controllers
import (
"io/ioutil"
"net/http"
"github.com/devxp-tech/go-skyapp01/pkd/github"
"github.com/gin-gonic/gin"
"github.com/gritzkoo/golang-health-checker-lw/pkg/healthchecker"
"github.com/sirupsen/logrus"
)
var version, _ = ioutil.ReadFile("rev.txt")
var checker = healthchecker.New(healthchecker.Config{
Name: "go-skyapp01",
Version: string(version),
Integrations: []healthchecker.Check{
{
Name: "GitHub Api Integration",
Handle: github.Status, // you should write your own tests to pass here!
},
},
})
// HealthCheckLiveness show a simple check
func HealthCheckLiveness(c *gin.Context) {
c.JSON(http.StatusOK, checker.Liveness())
}
// HealthCheckReadiness return a detailed status of all integrations in the list
func HealthCheckReadiness(c *gin.Context) {
result := checker.Readiness()
if !result.Status {
// the line below will print the error on logs, so you need to
// configure grafana or instana alarms with this context
logrus.WithField("error", result).Warning("Health check fails")
}
// the pod will always return a status 200 to prevent shotdown
c.JSON(http.StatusOK, result)
}