Files
trahn-trade/trahn-trade-backend/internal/api/health.go
2026-02-22 15:21:18 -05:00

30 lines
625 B
Go

package api
import (
"net/http"
"time"
)
type healthResponse struct {
Status string `json:"status"`
Timestamp string `json:"timestamp"`
Services healthServices `json:"services"`
}
type healthServices struct {
Database string `json:"database"`
}
func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {
dbStatus := "connected"
if err := s.pool.Ping(r.Context()); err != nil {
dbStatus = "disconnected"
}
writeJSON(w, http.StatusOK, healthResponse{
Status: "ok",
Timestamp: time.Now().UTC().Format(time.RFC3339),
Services: healthServices{Database: dbStatus},
})
}