Add enhanced health check endpoint

- Implement comprehensive health check with database ping
- Track and report server uptime
- Return proper HTTP status codes (503 if database is down)
- Add Swagger documentation for health endpoint
This commit is contained in:
2025-11-26 20:40:03 +01:00
parent 353a6c1f4b
commit daa7154b12
3 changed files with 91 additions and 6 deletions
+2 -5
View File
@@ -15,7 +15,7 @@ import (
_ "apocapoc-api/docs"
)
func NewRouter(corsOrigins string, habitHandlers *HabitHandlers, authHandlers *AuthHandlers, statsHandlers *StatsHandlers, jwtService *auth.JWTService) *chi.Mux {
func NewRouter(corsOrigins string, habitHandlers *HabitHandlers, authHandlers *AuthHandlers, statsHandlers *StatsHandlers, healthHandlers *HealthHandlers, jwtService *auth.JWTService) *chi.Mux {
r := chi.NewRouter()
r.Use(middleware.Logger)
@@ -34,10 +34,7 @@ func NewRouter(corsOrigins string, habitHandlers *HabitHandlers, authHandlers *A
httpSwagger.URL("/api/v1/docs/doc.json"),
))
r.Get("/api/v1/health", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"status":"ok"}`))
})
r.Get("/api/v1/health", healthHandlers.Health)
r.Route("/api/v1/auth", func(r chi.Router) {
r.Use(httprate.LimitByIP(10, 1*time.Minute))