package api import ( "context" "net/http" "time" "github.com/jackc/pgx/v5/pgxpool" ) type healthHandler struct { pool *pgxpool.Pool } func (h *healthHandler) live(w http.ResponseWriter, _ *http.Request) { writeJSON(w, http.StatusOK, map[string]string{"status": "ok"}) } func (h *healthHandler) ready(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 { writeJSON(w, http.StatusServiceUnavailable, map[string]string{ "status": "unavailable", "db": "down", }) return } writeJSON(w, http.StatusOK, map[string]string{ "status": "ok", "db": "up", }) }