|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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.POST("/qiniuyun/callback", hdl.FileImgCallback) //七牛云回调
- r.Use(mw.DB) // 以下接口需要用到数据库
- {
- r.POST("/login", hdl.Login)
- r.POST("/login/phone", hdl.LoginPhone)
- r.POST("/register", hdl.Register)
- }
- r.Use(mw.CheckBody) //body参数转换
- r.Use(mw.CheckSign) //签名校验
- {
- r.POST("/qiniuyun/upload", hdl.ImgReqUpload) //七牛云上传
- r.POST("/sms", hdl.Sms) //短信发送
- }
- r.Use(mw.Auth) // 以下接口需要JWT验证
- rRole(r.Group("/role")) //权限管理
- rQualification(r.Group("/qualification")) //资质
- rApplication(r.Group("/application")) //应用管理
- }
-
- 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 rQualification(r *gin.RouterGroup) {
- r.GET("/info", hdl.QualificationInfo) //资质认证-基本信息
- r.GET("/select/base", hdl.QualificationSelectBase) //资质认证-认证选择内容
- r.POST("/enterprise/save", hdl.QualificationEnterpriseSave) //资质认证-企业认证保存
- r.POST("/bank/save", hdl.QualificationBankSave) //资质认证-银行资质保存
- r.POST("/contact/save", hdl.QualificationContactSave) //资质认证-联系方式保存
- }
- func rApplication(r *gin.RouterGroup) {
- r.POST("/applet/list", hdl.AppletApplicationList) //小程序应用-列表数据
- r.POST("/applet/save", hdl.AppletApplicationSave) //小程序应用-新增或保存
- r.POST("/applet/ad/space/list", hdl.AppletApplicationAdSpaceList) //小程序应用-广告位列表数据
- r.POST("/applet/ad/space/save", hdl.AppletApplicationAdSpaceSave) //小程序应用-广告位新增
- }
|