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)) }