Files
spa-server/health/handler.go
T

36 lines
1.1 KiB
Go
Raw Permalink Normal View History

// Package health provides the /health HTTP handler for spa-server.
// The wire format is identical to web/health.Response so responses are
// consistent across all Einherjar modules — without importing the web module.
package health
import (
"encoding/json"
"net/http"
"code.nochebuena.dev/einherjar/contracts/logging"
)
// response mirrors web/health.Response: {"status":"UP","components":{}}.
type response struct {
Status string `json:"status"`
Components map[string]string `json:"components"`
}
type handler struct {
logger logging.Logger
}
// NewHandler returns an http.Handler that always responds 200 UP.
// spa-server has no external dependencies to probe; being reachable is the health check.
func NewHandler(logger logging.Logger) http.Handler {
return &handler{logger: logger}
}
func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(response{Status: "UP", Components: map[string]string{}}); err != nil {
h.logger.Error("health: encode response", err)
}
}