Files
sundynix-go/initialize/router.go
T
2025-05-08 23:03:00 +08:00

48 lines
1.1 KiB
Go

package initialize
import (
"fmt"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"sundynix-go/global"
"sundynix-go/middleware"
"sundynix-go/router"
)
// Routers 初始化总路由
func Routers() {
Router := gin.New()
Router.Use(gin.Recovery())
if gin.Mode() == gin.DebugMode {
Router.Use(gin.Logger())
}
// 系统组路由
systemRouter := router.GroupApp.System
NeedAuthGroup := Router.Group(global.Config.System.RouterPrefix)
PublicGroup := Router.Group(global.Config.System.RouterPrefix)
//鉴权中间件
NeedAuthGroup.Use(middleware.AuthMiddleware())
{
//无须鉴权的路由
systemRouter.InitAuthRouter(PublicGroup) //登录和验证码不需要鉴权
}
{
//需要鉴权的路由
systemRouter.InitUserRouter(NeedAuthGroup) //用户相关
systemRouter.InitClientRouter(NeedAuthGroup) //客户端相关
}
address := fmt.Sprintf(":%d", global.Config.System.Addr)
err := Router.Run(address)
if err != nil {
global.Logger.Error("Gin run failed", zap.Error(err))
}
global.Logger.Info("Gin run success", zap.String("address", address))
}