feat: 初始化路由组

This commit is contained in:
Blizzard
2025-04-26 22:41:16 +08:00
parent 5e41df7dc2
commit 77405783c6
17 changed files with 264 additions and 5 deletions
+45
View File
@@ -0,0 +1,45 @@
package initialize
import (
"fmt"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"sundynix-go/global"
"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.JWTAuthMiddleware())
{
//无须鉴权的路由
systemRouter.InitLoginRouter(PublicGroup) //登录和验证码不需要鉴权
}
{
//需要鉴权的路由
systemRouter.InitUserRouter(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))
}