ferry/router/router.go

83 lines
2.2 KiB
Go
Raw Normal View History

2020-07-13 20:33:20 +08:00
package router
import (
2020-07-15 01:40:56 +08:00
"ferry/apis/monitor"
"ferry/apis/system"
"ferry/handler"
2020-07-13 20:33:20 +08:00
"ferry/pkg/jwtauth"
jwt "ferry/pkg/jwtauth"
2020-07-15 01:40:56 +08:00
"ferry/router/process"
systemRouter "ferry/router/system"
ginSwagger "github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"
2020-07-13 20:33:20 +08:00
"github.com/gin-gonic/gin"
_ "github.com/gin-gonic/gin"
)
2020-07-15 01:40:56 +08:00
func InitSysRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.RouterGroup {
g := r.Group("")
sysBaseRouter(g)
// 静态文件
sysStaticFileRouter(g)
// swagger注意生产环境可以注释掉
sysSwaggerRouter(g)
2020-07-13 20:33:20 +08:00
2020-07-15 01:40:56 +08:00
// 无需认证
sysNoCheckRoleRouter(g)
// 需要认证
sysCheckRoleRouterInit(g, authMiddleware)
2020-07-13 20:33:20 +08:00
2020-07-15 01:40:56 +08:00
return g
2020-07-13 20:33:20 +08:00
}
2020-07-15 01:40:56 +08:00
func sysBaseRouter(r *gin.RouterGroup) {
r.GET("/", system.HelloWorld)
r.GET("/info", handler.Ping)
}
2020-07-13 20:33:20 +08:00
2020-07-15 01:40:56 +08:00
func sysStaticFileRouter(r *gin.RouterGroup) {
r.Static("/static", "./static")
}
2020-07-13 20:33:20 +08:00
2020-07-15 01:40:56 +08:00
func sysSwaggerRouter(r *gin.RouterGroup) {
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
2020-07-13 20:33:20 +08:00
}
2020-07-15 01:40:56 +08:00
func sysNoCheckRoleRouter(r *gin.RouterGroup) {
v1 := r.Group("/api/v1")
v1.GET("/monitor/server", monitor.ServerInfo)
v1.GET("/getCaptcha", system.GenerateCaptchaHandler)
v1.GET("/menuTreeselect", system.GetMenuTreeelect)
}
func sysCheckRoleRouterInit(r *gin.RouterGroup, authMiddleware *jwtauth.GinJWTMiddleware) {
r.POST("/login", authMiddleware.LoginHandler)
// Refresh time can be longer than token timeout
r.GET("/refresh_token", authMiddleware.RefreshHandler)
v1 := r.Group("/api/v1")
// 系统管理
systemRouter.RegisterPageRouter(v1, authMiddleware)
systemRouter.RegisterBaseRouter(v1, authMiddleware)
systemRouter.RegisterDeptRouter(v1, authMiddleware)
systemRouter.RegisterSysUserRouter(v1, authMiddleware)
systemRouter.RegisterRoleRouter(v1, authMiddleware)
systemRouter.RegisterUserCenterRouter(v1, authMiddleware)
systemRouter.RegisterPostRouter(v1, authMiddleware)
systemRouter.RegisterMenuRouter(v1, authMiddleware)
systemRouter.RegisterLoginLogRouter(v1, authMiddleware)
// 流程中心
process.RegisterClassifyRouter(v1, authMiddleware)
process.RegisterProcessRouter(v1, authMiddleware)
process.RegisterTaskRouter(v1, authMiddleware)
process.RegisterTplRouter(v1, authMiddleware)
process.RegisterWorkOrderRouter(v1, authMiddleware)
2020-07-13 20:33:20 +08:00
}