@@ -19,36 +19,36 @@ import (
19
19
type status string
20
20
21
21
const (
22
- // pass healthy (acceptable aliases: "ok" to support Node's Terminus and "up" for Java's SpringBoot)
22
+ // Pass healthy (acceptable aliases: "ok" to support Node's Terminus and "up" for Java's SpringBoot)
23
23
// fail unhealthy (acceptable aliases: "error" to support Node's Terminus and "down" for Java's SpringBoot), and
24
24
// warn healthy, with some concerns.
25
25
//
26
26
// ref https://datatracker.ietf.org/doc/html/draft-inadarei-api-health-check#section-3.1
27
27
// status: (required) indicates whether the service status is acceptable
28
28
// or not. API publishers SHOULD use following values for the field:
29
29
// The value of the status field is case-insensitive and is tightly
30
- // related with the HTTP response code returned by the health endpoint.
31
- // For "pass" status, HTTP response code in the 2xx-3xx range MUST be
32
- // used. For "fail" status, HTTP response code in the 4xx-5xx range
30
+ // related with the HTTP Response code returned by the health endpoint.
31
+ // For "pass" status, HTTP Response code in the 2xx-3xx range MUST be
32
+ // used. For "fail" status, HTTP Response code in the 4xx-5xx range
33
33
// MUST be used. In case of the "warn" status, endpoints MUST return
34
34
// HTTP status in the 2xx-3xx range, and additional information SHOULD
35
- // be provided, utilizing optional fields of the response .
36
- pass status = "pass"
37
- fail status = "fail"
35
+ // be provided, utilizing optional fields of the Response .
36
+ Pass status = "pass"
37
+ Fail status = "fail"
38
38
warn status = "warn"
39
39
)
40
40
41
41
func (s status ) ToHTTPStatus () int {
42
- if s == pass || s == warn {
42
+ if s == Pass || s == warn {
43
43
return http .StatusOK
44
44
}
45
45
return http .StatusFailedDependency
46
46
}
47
47
48
48
type checks map [string ][]componentStatus
49
49
50
- // response is the data returned by the health endpoint, which will be marshaled to JSON format
51
- type response struct {
50
+ // Response is the data returned by the health endpoint, which will be marshaled to JSON format
51
+ type Response struct {
52
52
Status status `json:"status"`
53
53
Description string `json:"description"` // a human-friendly description of the service
54
54
Checks checks `json:"checks,omitempty"` // The Checks Object, should be omitted on installation route
@@ -65,8 +65,8 @@ type componentStatus struct {
65
65
66
66
// Check is the health check API handler
67
67
func Check (w http.ResponseWriter , r * http.Request ) {
68
- rsp := response {
69
- Status : pass ,
68
+ rsp := Response {
69
+ Status : Pass ,
70
70
Description : setting .AppName ,
71
71
Checks : make (checks ),
72
72
}
@@ -77,8 +77,8 @@ func Check(w http.ResponseWriter, r *http.Request) {
77
77
statuses = append (statuses , checkCache (rsp .Checks ))
78
78
}
79
79
for _ , s := range statuses {
80
- if s != pass {
81
- rsp .Status = fail
80
+ if s != Pass {
81
+ rsp .Status = Fail
82
82
break
83
83
}
84
84
}
@@ -94,22 +94,22 @@ func Check(w http.ResponseWriter, r *http.Request) {
94
94
func checkDatabase (ctx context.Context , checks checks ) status {
95
95
st := componentStatus {}
96
96
if err := db .GetEngine (ctx ).Ping (); err != nil {
97
- st .Status = fail
97
+ st .Status = Fail
98
98
st .Time = getCheckTime ()
99
99
log .Error ("database ping failed with error: %v" , err )
100
100
} else {
101
- st .Status = pass
101
+ st .Status = Pass
102
102
st .Time = getCheckTime ()
103
103
}
104
104
105
- if setting .Database .Type .IsSQLite3 () && st .Status == pass {
105
+ if setting .Database .Type .IsSQLite3 () && st .Status == Pass {
106
106
if ! setting .EnableSQLite3 {
107
- st .Status = fail
107
+ st .Status = Fail
108
108
st .Time = getCheckTime ()
109
109
log .Error ("SQLite3 health check failed with error: %v" , "this Forgejo binary is built without SQLite3 enabled" )
110
110
} else {
111
111
if _ , err := os .Stat (setting .Database .Path ); err != nil {
112
- st .Status = fail
112
+ st .Status = Fail
113
113
st .Time = getCheckTime ()
114
114
log .Error ("SQLite3 file exists check failed with error: %v" , err )
115
115
}
@@ -124,11 +124,11 @@ func checkDatabase(ctx context.Context, checks checks) status {
124
124
func checkCache (checks checks ) status {
125
125
st := componentStatus {}
126
126
if err := cache .GetCache ().Ping (); err != nil {
127
- st .Status = fail
127
+ st .Status = Fail
128
128
st .Time = getCheckTime ()
129
129
log .Error ("cache ping failed with error: %v" , err )
130
130
} else {
131
- st .Status = pass
131
+ st .Status = Pass
132
132
st .Time = getCheckTime ()
133
133
}
134
134
checks ["cache:ping" ] = []componentStatus {st }
0 commit comments