package router import ( "applet/app/cfg" "applet/app/hdl" "applet/app/mw" _ "applet/docs" "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" ) // 初始化路由 func Init() *gin.Engine { // debug, release, test 项目阶段 mode := "release" if cfg.Debug { mode = "debug" } gin.SetMode(mode) //创建一个新的启动器 r := gin.New() r.GET("/api/swagger/*any", func(c *gin.Context) { //r.Use(mw.SwagAuth()) ginSwagger.DisablingWrapHandler(swaggerFiles.Handler, "SWAGGER")(c) }) r.Use(mw.ChangeHeader) // 是否打印访问日志, 在非正式环境都打印 if mode != "release" { r.Use(gin.Logger()) } r.Use(gin.Recovery()) // r.Use(mw.Limiter) //r.LoadHTMLGlob("static/html/*") r.GET("/favicon.ico", func(c *gin.Context) { c.Status(204) }) r.NoRoute(func(c *gin.Context) { c.JSON(404, gin.H{"code": 404, "msg": "page not found", "data": []struct{}{}}) }) r.NoMethod(func(c *gin.Context) { c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}}) }) r.Use(mw.Cors) route(r.Group("/api")) return r } func route(r *gin.RouterGroup) { r.GET("/test", hdl.Demo) wxOpenNotify := r.Group("/wxOpenNotify") { wxOpenNotify.Any("/:APPID/wechatMsgRecieve", hdl.WechatMsgRecieve) wxOpenNotify.Any("/setTicket", hdl.SetTicket) } r.Use(mw.DB) // 以下接口需要用到数据库 { r.POST("/login", hdl.Login) } r.Use(mw.CheckBody) //body参数转换 r.Use(mw.CheckSign) //签名校验 r.Use(mw.Auth) // 以下接口需要JWT验证 rRole(r.Group("/role")) //权限管理 rAgentQualification(r.Group("/agentQualification")) //渠道-资质 rMediumQualification(r.Group("/mediumQualification")) //媒体-资质 } func rRole(r *gin.RouterGroup) { r.GET("/roleList", hdl.RoleList) //角色列表 r.POST("/addRole", hdl.AddRole) //角色添加 r.POST("/roleBindPermissionGroup", hdl.RoleBindPermissionGroup) //角色绑定权限组 r.POST("/updateRoleState", hdl.UpdateRoleState) //修改角色状态 r.POST("/updateRole", hdl.UpdateRole) //修改角色状态 r.DELETE("/deleteRole/:id", hdl.DeleteRole) //删除角色 r.GET("/permissionGroupList", hdl.PermissionGroupList) //权限组列表 r.POST("/adminList", hdl.AdminList) //管理员列表 r.POST("/updateAdminState", hdl.UpdateAdminState) //修改管理员状态 r.POST("/updateAdmin", hdl.UpdateAdmin) //修改管理员信息 r.POST("/addAdmin", hdl.AddAdmin) //新增管理员 r.DELETE("/deleteAdmin/:adm_id", hdl.DeleteAdmin) //删除管理员 r.GET("/adminInfo", hdl.AdminInfo) //获取管理员信息 r.POST("/bindAdminRole", hdl.BindAdminRole) //绑定角色 } func rAgentQualification(r *gin.RouterGroup) { r.POST("/enterprise", hdl.AgentQualificationEnterprise) //企业主体资质 r.POST("/enterprise/audit", hdl.AgentQualificationEnterpriseAudit) //企业主体资质审核 } func rMediumQualification(r *gin.RouterGroup) { r.POST("/enterprise", hdl.MediumQualificationEnterprise) //企业主体资质 r.POST("/enterprise/audit", hdl.MediumQualificationEnterpriseAudit) //企业主体资质审核 }