init: initial commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sundynix-go/docs"
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/middleware"
|
||||
"sundynix-go/router"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
swaggerFiles "github.com/swaggo/files"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Routers 初始化总路由
|
||||
func Routers() {
|
||||
Router := gin.New()
|
||||
|
||||
Router.Use(gin.Recovery())
|
||||
if gin.Mode() == gin.DebugMode {
|
||||
Router.Use(gin.Logger())
|
||||
}
|
||||
docs.SwaggerInfo.BasePath = global.Config.System.RouterPrefix
|
||||
Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
// 系统组路由
|
||||
systemRouter := router.GroupApp.System
|
||||
plantGroup := router.GroupApp.Plant
|
||||
|
||||
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) //客户端相关
|
||||
systemRouter.InitRoleRouter(NeedAuthGroup) //角色相关
|
||||
systemRouter.InitMenuRouter(NeedAuthGroup) //菜单相关
|
||||
systemRouter.InitOssRouter(NeedAuthGroup) //OSS相关
|
||||
}
|
||||
|
||||
{
|
||||
//需要鉴权的路由
|
||||
plantGroup.InitPlantRouter(NeedAuthGroup)
|
||||
|
||||
}
|
||||
|
||||
address := fmt.Sprintf(":%d", global.Config.System.Addr)
|
||||
fmt.Printf(`
|
||||
欢迎使用 sundynix-plant-go
|
||||
项目地址:
|
||||
默认自动化文档地址:http://127.0.0.1%s/swagger/index.html
|
||||
默认前端文件运行地址:http://127.0.0.1:8080
|
||||
`, address)
|
||||
|
||||
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))
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user