-var pingResponseOK = map[string]string{"health": "OK"}
-
-// HealthCheckPingHandler processes "GET /_health/ping" requests
-func HealthCheckPingHandler(resp http.ResponseWriter, req *http.Request) {
- healthCheckDo(resp, req, pingResponseOK)
-}
-
-func healthCheckDo(resp http.ResponseWriter, req *http.Request, v interface{}) {
- msg, code := healthCheckAuth(resp, req)
- if msg != "" {
- http.Error(resp, msg, code)
- return
- }
-
- ok, err := json.Marshal(v)
- if err != nil {
- http.Error(resp, err.Error(), 500)
- }
-
- resp.Write(ok)
-}
-
-func healthCheckAuth(resp http.ResponseWriter, req *http.Request) (string, int) {
- if theConfig.ManagementToken == "" {
- return "disabled", http.StatusNotFound
- } else if h := req.Header.Get("Authorization"); h == "" {
- return "authorization required", http.StatusUnauthorized
- } else if h != "Bearer "+theConfig.ManagementToken {
- return "authorization error", http.StatusForbidden
- }
- return "", 0
-}
-