Начало реализации сервиса.

This commit is contained in:
Grbisba
2026-10-30 12:25:56 +03:00
parent 65003b6119
commit 20f2f00a60
52 changed files with 4351 additions and 1 deletions
@@ -0,0 +1,37 @@
package http
import (
"net/http"
"gitea.privcloud.tech/mtusi2026/internal/gen/contracts"
"gitea.privcloud.tech/mtusi2026/internal/pkg/apperr"
)
type HealthHandler struct {
*BaseHandler
server Server
}
func NewHealthHandler(base *BaseHandler, server Server) Handler {
return &HealthHandler{
BaseHandler: base,
server: server,
}
}
func (h *HealthHandler) RegisterRoutes() {
h.router.Get("/health/ready", h.Ready)
h.router.Get("/health/live", h.Live)
}
func (h *HealthHandler) Live(w http.ResponseWriter, _ *http.Request) {
h.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"))
return
}
h.JSONResponse(w, http.StatusOK, contracts.Health{Status: contracts.Ok})
}