package handlers import ( "net/http" "sneak.berlin/go/dnswatcher/internal/healthcheck" ) // HandleHealthCheck returns the health check handler. It answers 503 // Service Unavailable when the health check's status is error, so that // a container health check fails, and 200 OK otherwise. func (h *Handlers) HandleHealthCheck() http.HandlerFunc { return func( writer http.ResponseWriter, request *http.Request, ) { resp := h.hc.Check() code := http.StatusOK if resp.Status == healthcheck.StatusError { code = http.StatusServiceUnavailable } h.respondJSON(writer, request, resp, code) } }