|
- package handler
-
- import (
- "net/http"
-
- "github.com/AFASystems/presence/internal/pkg/api/response"
- "gorm.io/gorm"
- )
-
- // Health returns OK and status "ok". Useful for liveness.
- func Health(w http.ResponseWriter, r *http.Request) {
- response.JSON(w, http.StatusOK, map[string]string{"status": "ok"})
- }
-
- // Ready checks DB connectivity and returns 200 if ready, 503 otherwise.
- func Ready(db *gorm.DB) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- sqlDB, err := db.DB()
- if err != nil {
- response.Error(w, http.StatusServiceUnavailable, "not_ready", "database not available")
- return
- }
- if err := sqlDB.Ping(); err != nil {
- response.Error(w, http.StatusServiceUnavailable, "not_ready", "database ping failed")
- return
- }
- response.JSON(w, http.StatusOK, map[string]string{"status": "ready"})
- }
- }
|