Files
ez-api/internal/api/health_handler.go
2025-12-21 20:22:56 +08:00

38 lines
951 B
Go

package api
import (
"net/http"
"github.com/ez-api/ez-api/internal/service"
"github.com/gin-gonic/gin"
)
type HealthHandler struct {
svc *service.HealthCheckService
}
func NewHealthHandler(svc *service.HealthCheckService) *HealthHandler {
return &HealthHandler{svc: svc}
}
// TestDeps godoc
// @Summary Test dependency connectivity
// @Description Checks Redis/PostgreSQL connections and reports status
// @Tags system
// @Produce json
// @Success 200 {object} service.HealthStatus
// @Failure 503 {object} service.HealthStatus
// @Router /api/status/test [get]
func (h *HealthHandler) TestDeps(c *gin.Context) {
if h == nil || h.svc == nil {
c.JSON(http.StatusServiceUnavailable, gin.H{"status": "down"})
return
}
status := h.svc.Check(c.Request.Context())
httpStatus := http.StatusOK
if status.Status == "down" {
httpStatus = http.StatusServiceUnavailable
}
c.JSON(httpStatus, status)
}