feat(app) lab2 prepared for mr

This commit is contained in:
imadev
2026-10-23 18:55:20 +03:00
parent 1db3953226
commit f6e74247fd
57 changed files with 2367 additions and 660 deletions
+35 -7
View File
@@ -3,25 +3,53 @@ package health
import (
"sync/atomic"
"gitflic.ru/project/bulla-max/mtusi2026lab1/internal/common"
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal/common"
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal/session"
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal/store"
"github.com/gofiber/fiber/v3"
)
type Handler struct {
store *store.Store
sessions *session.Store
}
func NewHandler(st *store.Store, sessions *session.Store) *Handler {
return &Handler{store: st, sessions: sessions}
}
var shuttingDown atomic.Bool
func SignalShutdown() {
shuttingDown.Store(true)
}
func live(c fiber.Ctx) error {
return c.JSON(fiber.Map{"status": "ok"})
type Status struct {
Status string `json:"status"`
}
func ready(c fiber.Ctx) error {
func (h *Handler) Live(c fiber.Ctx) error {
return c.JSON(Status{Status: "ok"})
}
// Ready answers whether the synchronous mandatory path can be served. Both
// PostgreSQL and Redis are critical here: business data and sessions live in
// them respectively.
func (h *Handler) Ready(c fiber.Ctx) error {
if shuttingDown.Load() {
return common.SendError(c, fiber.StatusInternalServerError,
common.ErrorCodeInternal, "app currently shutting down")
return common.SendError(c, fiber.StatusServiceUnavailable,
common.ErrorCodeUnavailable, "service is shutting down")
}
return c.JSON(fiber.Map{"status": "ok"})
if err := h.store.Ping(c.Context()); err != nil {
return common.SendError(c, fiber.StatusServiceUnavailable,
common.ErrorCodeUnavailable, "database unavailable")
}
if err := h.sessions.Ping(c.Context()); err != nil {
return common.SendError(c, fiber.StatusServiceUnavailable,
common.ErrorCodeUnavailable, "session store unavailable")
}
return c.JSON(Status{Status: "ok"})
}