Реализация на 4

This commit is contained in:
Grbisba
2026-11-05 14:24:40 +03:00
parent 20f2f00a60
commit 8d44c74535
85 changed files with 3601 additions and 1109 deletions
@@ -5,33 +5,35 @@ import (
"gitea.privcloud.tech/mtusi2026/internal/gen/contracts"
"gitea.privcloud.tech/mtusi2026/internal/pkg/apperr"
"gitea.privcloud.tech/mtusi2026/internal/pkg/rest/framework"
"gitea.privcloud.tech/mtusi2026/internal/pkg/rest/router"
)
type HealthHandler struct {
*BaseHandler
router router.Router
server Server
}
func NewHealthHandler(base *BaseHandler, server Server) Handler {
func NewHealthHandler(r router.Router, server Server) Handler {
return &HealthHandler{
BaseHandler: base,
server: server,
router: r,
server: server,
}
}
func (h *HealthHandler) RegisterRoutes() {
h.router.Get("/health/ready", h.Ready)
h.router.Get("/health/live", h.Live)
h.router.Public(http.MethodGet, "/health/ready", h.Ready)
h.router.Public(http.MethodGet, "/health/live", h.Live)
}
func (h *HealthHandler) Live(w http.ResponseWriter, _ *http.Request) {
h.JSONResponse(w, http.StatusOK, contracts.Health{Status: contracts.Ok})
framework.JSONResponse(w, http.StatusOK, contracts.Health{Status: contracts.Ok})
}
func (h *HealthHandler) Ready(w http.ResponseWriter, r *http.Request) {
if !h.server.Ready() {
h.JSONError(r.Context(), w, apperr.New(apperr.CodeUnavailable, "server is not ready"))
framework.JSONError(r.Context(), w, apperr.New(apperr.CodeUnavailable, "server is not ready"))
return
}
h.JSONResponse(w, http.StatusOK, contracts.Health{Status: contracts.Ok})
framework.JSONResponse(w, http.StatusOK, contracts.Health{Status: contracts.Ok})
}