CUB-119: add GET /api/health endpoint to Go backend router #47

Open
Dex wants to merge 1 commits from agent/dex/CUB-119-go-backend-scaffold into dev
Showing only changes of commit 4509b0c217 - Show all commits
+15
View File
@@ -65,6 +65,21 @@ func New(deps *Dependencies) *chi.Mux {
// ── API v1 routes ────────────────────────────────────────────────────── // ── API v1 routes ──────────────────────────────────────────────────────
r.Route("/api", func(api chi.Router) { r.Route("/api", func(api chi.Router) {
// Health check (under /api)
api.Get("/health", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
status := "ok"
if deps.Pool != nil {
ctx, cancel := context.WithTimeout(r.Context(), 3*time.Second)
defer cancel()
if err := deps.Pool.Ping(ctx); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
status = "db_unhealthy"
}
}
w.Write([]byte(`{"status":"` + status + `"}`))
})
// Agents CRUD // Agents CRUD
api.Route("/agents", func(agents chi.Router) { api.Route("/agents", func(agents chi.Router) {
agents.Get("/", deps.Handler.ListAgents) // GET /api/agents agents.Get("/", deps.Handler.ListAgents) // GET /api/agents