广告平台(总站长使用)
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

105 linhas
3.5 KiB

  1. package router
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/hdl"
  5. "applet/app/mw"
  6. _ "applet/docs"
  7. "github.com/gin-gonic/gin"
  8. swaggerFiles "github.com/swaggo/files"
  9. ginSwagger "github.com/swaggo/gin-swagger"
  10. )
  11. // 初始化路由
  12. func Init() *gin.Engine {
  13. // debug, release, test 项目阶段
  14. mode := "release"
  15. if cfg.Debug {
  16. mode = "debug"
  17. }
  18. gin.SetMode(mode)
  19. //创建一个新的启动器
  20. r := gin.New()
  21. r.GET("/api/swagger/*any", func(c *gin.Context) {
  22. //r.Use(mw.SwagAuth())
  23. ginSwagger.DisablingWrapHandler(swaggerFiles.Handler, "SWAGGER")(c)
  24. })
  25. r.Use(mw.ChangeHeader)
  26. // 是否打印访问日志, 在非正式环境都打印
  27. if mode != "release" {
  28. r.Use(gin.Logger())
  29. }
  30. r.Use(gin.Recovery())
  31. // r.Use(mw.Limiter)
  32. r.Delims("<<<", ">>>").LoadHTMLGlob("static/html/*")
  33. r.GET("/favicon.ico", func(c *gin.Context) {
  34. c.Status(204)
  35. })
  36. r.NoRoute(func(c *gin.Context) {
  37. c.JSON(404, gin.H{"code": 404, "msg": "page not found", "data": []struct{}{}})
  38. })
  39. r.NoMethod(func(c *gin.Context) {
  40. c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}})
  41. })
  42. r.Use(mw.Cors)
  43. route(r.Group("/api"))
  44. return r
  45. }
  46. func route(r *gin.RouterGroup) {
  47. r.Static("/static", "./static")
  48. r.GET("/test", hdl.Demo)
  49. wxOpenNotify := r.Group("/wxOpen")
  50. {
  51. wxOpenNotify.Any("/:APPID/wechatMsgRecieve", hdl.WechatMsgRecieve)
  52. wxOpenNotify.Any("/setTicket", hdl.SetTicket)
  53. wxOpenNotify.GET("/getPreAuthCode", hdl.GetPreAuthCode)
  54. wxOpenNotify.GET("/getAuthUrlCallBack", hdl.GetAuthUrlCallBack)
  55. }
  56. r.Use(mw.DB) // 以下接口需要用到数据库
  57. {
  58. r.POST("/login", hdl.Login)
  59. }
  60. r.Use(mw.CheckBody) //body参数转换
  61. r.Use(mw.CheckSign) //签名校验
  62. r.Use(mw.Auth) // 以下接口需要JWT验证
  63. rRole(r.Group("/role")) //权限管理
  64. rDataCenter(r.Group("/dataCenter")) //数据中心
  65. rSmsCenter(r.Group("/smsCenter")) //短信中心
  66. }
  67. func rRole(r *gin.RouterGroup) {
  68. r.GET("/roleList", hdl.RoleList) //角色列表
  69. r.POST("/addRole", hdl.AddRole) //角色添加
  70. r.POST("/roleBindPermissionGroup", hdl.RoleBindPermissionGroup) //角色绑定权限组
  71. r.POST("/updateRoleState", hdl.UpdateRoleState) //修改角色状态
  72. r.POST("/updateRole", hdl.UpdateRole) //修改角色状态
  73. r.DELETE("/deleteRole/:id", hdl.DeleteRole) //删除角色
  74. r.GET("/permissionGroupList", hdl.PermissionGroupList) //权限组列表
  75. r.POST("/adminList", hdl.AdminList) //管理员列表
  76. r.POST("/updateAdminState", hdl.UpdateAdminState) //修改管理员状态
  77. r.POST("/updateAdmin", hdl.UpdateAdmin) //修改管理员信息
  78. r.POST("/addAdmin", hdl.AddAdmin) //新增管理员
  79. r.DELETE("/deleteAdmin/:adm_id", hdl.DeleteAdmin) //删除管理员
  80. r.GET("/adminInfo", hdl.AdminInfo) //获取管理员信息
  81. r.POST("/bindAdminRole", hdl.BindAdminRole) //绑定角色
  82. }
  83. func rDataCenter(r *gin.RouterGroup) {
  84. r.POST("/original/data/list", hdl.OriginalDataList) //数据中心-原始数据
  85. r.POST("/generate/data/list", hdl.GenerateDataList) //数据中心-分成数据
  86. r.POST("/generate/data/detail", hdl.GenerateDataDetail) //数据中心-分成数据-详情
  87. }
  88. func rSmsCenter(r *gin.RouterGroup) {
  89. r.POST("/list", hdl.SmsList)
  90. r.POST("/detail", hdl.SmsDetail)
  91. r.POST("/update", hdl.SmsUpdate)
  92. }