health.go 581 B

123456789101112131415161718192021222324252627
  1. package health
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "github.com/cloudflare/cfssl/api"
  6. )
  7. // Response contains the response to the /health API
  8. type Response struct {
  9. Healthy bool `json:"healthy"`
  10. }
  11. func healthHandler(w http.ResponseWriter, r *http.Request) error {
  12. response := api.NewSuccessResponse(&Response{Healthy: true})
  13. return json.NewEncoder(w).Encode(response)
  14. }
  15. // NewHealthCheck creates a new handler to serve health checks.
  16. func NewHealthCheck() http.Handler {
  17. return api.HTTPHandler{
  18. Handler: api.HandlerFunc(healthHandler),
  19. Methods: []string{"GET"},
  20. }
  21. }