-
Notifications
You must be signed in to change notification settings - Fork 90
/
healthz.go
53 lines (43 loc) · 1.05 KB
/
healthz.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
package handlers
import (
"net/http"
"github.com/replicatedhq/kots/pkg/buildversion"
)
type HealthzResponse struct {
Version string `json:"version"`
GitSHA string `json:"gitSha"`
Status StatusResponse `json:"status"`
}
type StatusResponse struct {
Database DatabaseResponse `json:"database"`
Storage StorageResponse `json:"storage"`
}
type DatabaseResponse struct {
Connected bool `json:"connected"`
}
type StorageResponse struct {
Available bool `json:"available"`
}
// Healthz route is UNAUTHENTICATED
func (h *Handler) Healthz(w http.ResponseWriter, r *http.Request) {
// TODO
isDatabaseConnected := true
isStorageAvailable := true
healthzResponse := HealthzResponse{
Version: buildversion.Version(),
GitSHA: "test",
Status: StatusResponse{
Database: DatabaseResponse{
Connected: isDatabaseConnected,
},
Storage: StorageResponse{
Available: isStorageAvailable,
},
},
}
statusCode := 200
if !isDatabaseConnected || !isStorageAvailable {
statusCode = 419
}
JSON(w, statusCode, healthzResponse)
}