(isHealthy func() bool)
| 19 | import "net/http" |
| 20 | |
| 21 | func HealthcheckHandler(isHealthy func() bool) http.HandlerFunc { |
| 22 | return func(w http.ResponseWriter, r *http.Request) { |
| 23 | if !isHealthy() { |
| 24 | w.WriteHeader(http.StatusInternalServerError) |
| 25 | _, _ = w.Write([]byte("unhealthy")) |
| 26 | return |
| 27 | } |
| 28 | |
| 29 | w.WriteHeader(http.StatusOK) |
| 30 | _, _ = w.Write([]byte("healthy")) |
| 31 | } |
| 32 | } |