mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
38 lines
951 B
Go
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)
|
|
}
|