蛋蛋星球 后台端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

108 行
3.8 KiB

  1. package router
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/hdl"
  5. "applet/app/hdl/comm"
  6. "applet/app/hdl/institutional_management/egg_energy"
  7. "applet/app/hdl/institutional_management/public_platoon"
  8. "applet/app/mw"
  9. _ "applet/docs"
  10. "github.com/gin-gonic/gin"
  11. swaggerFiles "github.com/swaggo/files"
  12. ginSwagger "github.com/swaggo/gin-swagger"
  13. )
  14. // 初始化路由
  15. func Init() *gin.Engine {
  16. // debug, release, test 项目阶段
  17. mode := "release"
  18. if cfg.Debug {
  19. mode = "debug"
  20. }
  21. gin.SetMode(mode)
  22. //创建一个新的启动器
  23. r := gin.New()
  24. r.GET("/api/swagger/*any", func(c *gin.Context) {
  25. // r.Use(mw.SwagAuth())
  26. ginSwagger.DisablingWrapHandler(swaggerFiles.Handler, "SWAGGER")(c)
  27. })
  28. // 是否打印访问日志, 在非正式环境都打印
  29. if mode != "release" {
  30. r.Use(gin.Logger())
  31. }
  32. r.Use(gin.Recovery())
  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.GET("/test", hdl.Demo)
  48. r.POST("/login", hdl.Login)
  49. r.Use(mw.Auth) // 以下接口需要JWT验证
  50. rComm(r.Group("/comm"))
  51. r.Use(mw.CheckPermission) // 检测权限
  52. rInstitutionalManagement(r.Group("/institutionalManagement"))
  53. }
  54. func rInstitutionalManagement(r *gin.RouterGroup) { //制度管理
  55. rPublicPlatoon := r.Group("/publicPlatoon") //公排设置
  56. {
  57. rPublicPlatoon.GET("/getBasic", public_platoon.GetPublicPlatoonBasic)
  58. rPublicPlatoon.PUT("/updateBasic", public_platoon.UpdatePublicPlatoonBasic)
  59. rPublicPlatoon.GET("/relationshipMap", public_platoon.GetRelationshipMap)
  60. rPublicPlatoon.GET("/findUserRelationshipMap", public_platoon.FindUserRelationshipMap)
  61. rPublicPlatoon.GET("/findSubUserRelationshipMap", public_platoon.FindSubUserRelationshipMap)
  62. rPublicPlatoon.POST("/exchangeUserPosition", public_platoon.ExchangeUserPosition)
  63. rPublicPlatoonUserFreePunish := rPublicPlatoon.Group("/publicPlatoonUserFreePunish")
  64. {
  65. rPublicPlatoonUserFreePunish.POST("/index", public_platoon.GetFreePublishUser)
  66. rPublicPlatoonUserFreePunish.POST("/save", public_platoon.AddFreePublishUser)
  67. }
  68. rCommunityDividends := rPublicPlatoon.Group("/communityDividends")
  69. {
  70. rCommunityDividends.POST("/communityDividendsList", public_platoon.ListCommunityDividends)
  71. rCommunityDividends.POST("/communityDividendsAdd", public_platoon.AddCommunityDividends)
  72. rCommunityDividends.POST("/communityDividendsWithUserList", public_platoon.ListCommunityDividendsWithUser)
  73. rCommunityDividends.POST("/communityDividendsWithUserAdd", public_platoon.AddCommunityDividendsWithUser)
  74. }
  75. rUserDailyActivityAnalysis := rPublicPlatoon.Group("/userDailyActivityAnalysis")
  76. {
  77. rUserDailyActivityAnalysis.POST("/index", public_platoon.UserDailyActivityAnalysis)
  78. }
  79. }
  80. rEggEnergy := r.Group("/eggEnergy")
  81. {
  82. rEggEnergy.GET("/getBasic", egg_energy.GetEggEnergyBasic)
  83. rEggEnergy.POST("/updateBasic", egg_energy.UpdateEggEnergyBasic)
  84. rEggEnergyUserCoin := rEggEnergy.Group("/userCoin")
  85. {
  86. rEggEnergyUserCoin.POST("/activePointsUserCoinList", egg_energy.GetActivePointsUserCoinList)
  87. rEggEnergyUserCoin.POST("/activePointsUserCoinFlowList", egg_energy.GetActivePointsUserCoinFlowList)
  88. rEggEnergyUserCoin.POST("/greenEnergyUserCoinList", egg_energy.GetGreenEnergyUserCoinList)
  89. rEggEnergyUserCoin.POST("/greenEnergyUserCoinFlowList", egg_energy.GetGreenEnergyUserCoinFlowList)
  90. }
  91. rEggEnergyAvailableEnergy := rPublicPlatoon.Group("/availableEnergy")
  92. {
  93. rEggEnergyAvailableEnergy.POST("/list", egg_energy.DynamicDataFlowList)
  94. }
  95. }
  96. }
  97. func rComm(r *gin.RouterGroup) {
  98. r.POST("/getMenuList", comm.MenuList) // 获取菜单栏列表
  99. }