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) r.Use(mw.DB) // 以下接口需要用到数据库 { r.POST("/login", hdl.Login) } r.Use(mw.CheckBody) //body参数转换 r.Use(mw.CheckSign) //签名校验 r.POST("/registerForMedium", hdl.RegisterForMedium) r.POST("/registerForAgent", hdl.RegisterForAgent) r.Use(mw.Auth) // 以下接口需要JWT验证 rRole(r.Group("/role")) //权限管理 rAgentQualification(r.Group("/agentQualification")) //渠道-资质 rMediumQualification(r.Group("/mediumQualification")) //媒体-资质 rSetCenter(r.Group("/setCenter")) //设置中心 rMedium(r.Group("/medium")) //媒体中心 } 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) //企业主体资质审核 r.POST("/bank", hdl.AgentQualificationBank) //银行资质 r.POST("/bank/audit", hdl.AgentQualificationBankAudit) //银行审核 r.POST("/contact", hdl.AgentQualificationContactInfo) //联系方式 r.POST("/contact/audit", hdl.AgentQualificationContactInfoAudit) //联系方式 } func rMediumQualification(r *gin.RouterGroup) { r.POST("/enterprise", hdl.MediumQualificationEnterprise) //企业主体资质 r.POST("/enterprise/audit", hdl.MediumQualificationEnterpriseAudit) //企业主体资质审核 r.POST("/bank", hdl.MediumQualificationBank) //银行资质 r.POST("/bank/audit", hdl.MediumQualificationBankAudit) //银行审核 r.POST("/contact", hdl.MediumQualificationContactInfo) //联系方式 r.POST("/contact/audit", hdl.MediumQualificationContactInfoAudit) //联系方式 } func rSetCenter(r *gin.RouterGroup) { rBasicSetCenter := r.Group("/basic") { rBasicSetCenter.POST("/setOss", hdl.SetOss) rBasicSetCenter.GET("/getOss", hdl.GetOss) rBasicSetCenter.POST("/wxOpenSet", hdl.WxOpenSet) rBasicSetCenter.GET("/wxOpenGet", hdl.WxOpenGet) rBasicSetCenter.POST("/setMob", hdl.SetMob) rBasicSetCenter.GET("/getMob", hdl.GetMob) } rAppletSetCenter := r.Group("/applet") { rAppletSetCenter.GET("/list", hdl.AppletList) rAppletSetCenter.POST("/add", hdl.AppletAdd) rAppletSetCenter.POST("/update", hdl.AppletUpdate) rAppletSetCenter.DELETE("/delete/:id", hdl.AppletDelete) rAppletSetCenter.GET("/authorize", hdl.AppletAuthorize) rAppletSetCenter.GET("/unauthorized", hdl.AppletUnauthorized) } rShareSetCenter := r.Group("/share") { rShareSetCenter.GET("/index", hdl.ShareIndex) } } func rMedium(r *gin.RouterGroup) { r.POST("/applet/application/medium/list", hdl.AppletApplicationMediumList) //应用管理-媒体列表 r.POST("/applet/application/list", hdl.AppletApplicationList) //小程序应用-列表数据 r.POST("/applet/application/audit", hdl.AppletApplicationAudit) //小程序应用-审核 r.POST("/applet/application/ad/space/medium/list", hdl.AppletApplicationAdSpaceMediumList) //广告管理-媒体列表 r.POST("/applet/application/ad/space/list", hdl.AppletApplicationAdSpaceList) //小程序应用-广告位列表数据 r.POST("/applet/application/ad/space/audit", hdl.AppletApplicationAdSpaceAudit) //小程序应用-广告位审核 }