Перенести решение лабораторной 1 как основу для лабораторной 2

This commit is contained in:
2026-10-06 11:54:05 +03:00
parent 65003b6119
commit 5c3f2bfad0
54 changed files with 4472 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
// Package health serves the probes. Liveness only proves the process
// answers; readiness is switched off during shutdown so an orchestrator stops
// routing new traffic before the listener closes.
package health
import (
"net/http"
"sync/atomic"
"github.com/gin-gonic/gin"
"messenger/internal/platform/apperr"
"messenger/internal/platform/httpx"
)
type Handler struct {
ready atomic.Bool
}
type status struct {
Status string `json:"status"`
}
func New() *Handler {
h := &Handler{}
h.ready.Store(true)
return h
}
func (h *Handler) SetReady(ready bool) {
h.ready.Store(ready)
}
func (h *Handler) IsReady() bool {
return h.ready.Load()
}
func (h *Handler) Register(r gin.IRouter) {
r.GET("/health/live", h.live)
r.GET("/health/ready", h.readyz)
}
func (h *Handler) live(c *gin.Context) {
httpx.JSON(c, http.StatusOK, status{Status: "ok"})
}
func (h *Handler) readyz(c *gin.Context) {
if !h.ready.Load() {
httpx.Error(c, apperr.Unavailable("service is shutting down"))
return
}
httpx.JSON(c, http.StatusOK, status{Status: "ok"})
}