Files
online-backend/internal/handlers/manager/manager.go
2026-07-15 18:08:19 +05:00

54 lines
1.3 KiB
Go
Executable File

package handlermanager
import (
"net/http"
"online-back/internal/cards"
"online-back/internal/config"
"online-back/internal/identity"
"online-back/internal/lending"
"online-back/internal/org"
"online-back/pkg/logging"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v4/pgxpool"
)
const adminAPIPrefix = "/api/admin"
func New(cfg *config.Config, client *pgxpool.Pool, logger *logging.Logger) *gin.Engine {
if cfg.IsDebug != nil && !*cfg.IsDebug {
gin.SetMode(gin.ReleaseMode)
}
router := gin.New()
router.Use(gin.Recovery(), gin.Logger())
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{
http.MethodGet,
http.MethodPost,
http.MethodPut,
http.MethodDelete,
},
AllowHeaders: []string{
"Content-Type",
"Authorization",
"Cache-Control",
},
ExposeHeaders: []string{"Content-Length"},
}))
adminGroup := router.Group(adminAPIPrefix)
// Each bounded context registers its own modules' handlers.
// Add new modules inside the relevant context's router.go rather than here.
identity.Register(adminGroup, client, logger)
org.Register(adminGroup, client, logger)
lending.Register(adminGroup, client, logger)
cards.Register(adminGroup, client, logger)
return router
}