2022-05-11 18:47:31 -04:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"npm/internal/acme"
|
|
|
|
h "npm/internal/api/http"
|
|
|
|
"npm/internal/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
type healthCheckResponse struct {
|
2023-07-20 01:19:42 -04:00
|
|
|
Version string `json:"version"`
|
|
|
|
Commit string `json:"commit"`
|
|
|
|
AcmeShVersion string `json:"acme.sh"`
|
|
|
|
Healthy bool `json:"healthy"`
|
|
|
|
IsSetup bool `json:"setup"`
|
2022-05-11 18:47:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Health returns the health of the api
|
|
|
|
// Route: GET /health
|
|
|
|
func Health() func(http.ResponseWriter, *http.Request) {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
health := healthCheckResponse{
|
2023-07-20 01:19:42 -04:00
|
|
|
Version: config.Version,
|
|
|
|
Commit: config.Commit,
|
|
|
|
Healthy: true,
|
|
|
|
IsSetup: config.IsSetup,
|
|
|
|
AcmeShVersion: acme.GetAcmeShVersion(),
|
2022-05-11 18:47:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
h.ResultResponseJSON(w, r, http.StatusOK, health)
|
|
|
|
}
|
|
|
|
}
|