// SPDX-License-Identifier: GPL-2.0-or-later // Copyright (C) 2026 Bryan Joshua Pedini package main import ( "context" "encoding/json" "net/http" "time" ) // handleHealthz pings the DB with a short timeout and reports status. No // auth, no data exposed beyond ok/unhealthy. func (s *WebServer) handleHealthz(w http.ResponseWriter, r *http.Request) { ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second) defer cancel() w.Header().Set("Content-Type", "application/json") if err := s.DB.PingContext(ctx); err != nil { s.Logger.Error("healthz ping failed", "error", err) w.WriteHeader(http.StatusServiceUnavailable) json.NewEncoder(w).Encode(map[string]string{"status": "unhealthy"}) return } w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(map[string]string{"status": "ok"}) }