// Package fiber implements the messenger HTTP transport using Fiber. package fiber import ( "fmt" "sync/atomic" "github.com/gofiber/fiber/v2" "go.lab260.ru/fielderr" "go.uber.org/zap" "gitea.privcloud.tech/vlad_marlo/mtusi2026lab2/internal/admission" "gitea.privcloud.tech/vlad_marlo/mtusi2026lab2/internal/config" "gitea.privcloud.tech/vlad_marlo/mtusi2026lab2/internal/controller" "gitea.privcloud.tech/vlad_marlo/mtusi2026lab2/internal/service" ) // Controller owns the HTTP server and delegates business operations to Service. // Its configuration is copied at construction and must not change during serving. // Fx manages its listener through Start and Stop. type Controller struct { log *zap.Logger cfg config.Controller service service.Service server *fiber.App errorRegistry *fielderr.Registry admission admission.Distributed auth service.Authentication readiness Readiness stopping atomic.Bool serveDone chan error } var _ controller.Controller = (*Controller)(nil) // New validates dependencies and prepares the server without opening a listener. // Routing, middleware and Fiber configuration are installed by configure. func New(log *zap.Logger, cfg *config.Controller, svc service.Service, registry *fielderr.Registry, limiter admission.Distributed, auth service.Authentication, readiness Readiness) (*Controller, error) { if err := cfg.Validate(); err != nil { return nil, err } if log == nil || svc == nil || registry == nil || limiter == nil || auth == nil || readiness == nil { return nil, fmt.Errorf("HTTP logger, service, error registry and admission limiter are required") } ctrl := &Controller{ log: log.Named("controller.http.fiber"), cfg: *cfg, service: svc, errorRegistry: registry, admission: limiter, auth: auth, readiness: readiness, serveDone: make(chan error, 1), } ctrl.configure() return ctrl, nil }