package httpapi import ( "context" "net/http" "time" "github.com/jackc/pgx/v5/pgxpool" ) // HealthHandler exposes /healthz (liveness) and /readyz (readiness + DB ping). type HealthHandler struct { Pool *pgxpool.Pool } func (h *HealthHandler) Healthz(w http.ResponseWriter, r *http.Request) { renderJSON(w, http.StatusOK, map[string]string{"status": "ok"}) } func (h *HealthHandler) Readyz(w http.ResponseWriter, r *http.Request) { ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second) defer cancel() if err := h.Pool.Ping(ctx); err != nil { renderError(w, http.StatusServiceUnavailable, "Database unavailable", err.Error()) return } renderJSON(w, http.StatusOK, map[string]string{"status": "ready"}) }