1package api 2 3import ( 4 "errors" 5 "net/http" 6 7 "github.com/docker/distribution/health" 8) 9 10var ( 11 updater = health.NewStatusUpdater() 12) 13 14// DownHandler registers a manual_http_status that always returns an Error 15func DownHandler(w http.ResponseWriter, r *http.Request) { 16 if r.Method == "POST" { 17 updater.Update(errors.New("manual Check")) 18 } else { 19 w.WriteHeader(http.StatusNotFound) 20 } 21} 22 23// UpHandler registers a manual_http_status that always returns nil 24func UpHandler(w http.ResponseWriter, r *http.Request) { 25 if r.Method == "POST" { 26 updater.Update(nil) 27 } else { 28 w.WriteHeader(http.StatusNotFound) 29 } 30} 31 32// init sets up the two endpoints to bring the service up and down 33func init() { 34 health.Register("manual_http_status", updater) 35 http.HandleFunc("/debug/health/down", DownHandler) 36 http.HandleFunc("/debug/health/up", UpHandler) 37} 38