蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

89 lines
2.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/public_platoon"
  7. "applet/app/mw"
  8. _ "applet/docs"
  9. "github.com/gin-gonic/gin"
  10. swaggerFiles "github.com/swaggo/files"
  11. ginSwagger "github.com/swaggo/gin-swagger"
  12. )
  13. // 初始化路由
  14. func Init() *gin.Engine {
  15. // debug, release, test 项目阶段
  16. mode := "release"
  17. if cfg.Debug {
  18. mode = "debug"
  19. }
  20. gin.SetMode(mode)
  21. //创建一个新的启动器
  22. r := gin.New()
  23. r.GET("/api/swagger/*any", func(c *gin.Context) {
  24. // r.Use(mw.SwagAuth())
  25. ginSwagger.DisablingWrapHandler(swaggerFiles.Handler, "SWAGGER")(c)
  26. })
  27. // 是否打印访问日志, 在非正式环境都打印
  28. if mode != "release" {
  29. r.Use(gin.Logger())
  30. }
  31. r.Use(gin.Recovery())
  32. r.GET("/favicon.ico", func(c *gin.Context) {
  33. c.Status(204)
  34. })
  35. r.NoRoute(func(c *gin.Context) {
  36. c.JSON(404, gin.H{"code": 404, "msg": "page not found", "data": []struct{}{}})
  37. })
  38. r.NoMethod(func(c *gin.Context) {
  39. c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}})
  40. })
  41. r.Use(mw.Cors)
  42. route(r.Group("/api"))
  43. return r
  44. }
  45. func route(r *gin.RouterGroup) {
  46. r.GET("/test", hdl.Demo)
  47. r.POST("/login", hdl.Login)
  48. //r.Use(mw.Auth) // 以下接口需要JWT验证
  49. rComm(r.Group("/comm"))
  50. //r.Use(mw.CheckPermission) // 检测权限
  51. rInstitutionalManagement(r.Group("/institutionalManagement"))
  52. }
  53. func rInstitutionalManagement(r *gin.RouterGroup) { //制度管理
  54. rPublicPlatoon := r.Group("/publicPlatoon") //公排设置
  55. {
  56. rPublicPlatoon.GET("/getBasic", public_platoon.GetPublicPlatoonBasic)
  57. rPublicPlatoon.PUT("/updateBasic", public_platoon.UpdatePublicPlatoonBasic)
  58. rPublicPlatoon.GET("/relationshipMap", public_platoon.GetRelationshipMap)
  59. rPublicPlatoon.GET("/findUserRelationshipMap", public_platoon.FindUserRelationshipMap)
  60. rPublicPlatoon.GET("/findSubUserRelationshipMap", public_platoon.FindSubUserRelationshipMap)
  61. rPublicPlatoon.POST("/exchangeUserPosition", public_platoon.ExchangeUserPosition)
  62. rPublicPlatoonUserFreePunish := rPublicPlatoon.Group("/publicPlatoonUserFreePunish")
  63. {
  64. rPublicPlatoonUserFreePunish.POST("/index", public_platoon.GetFreePublishUser)
  65. rPublicPlatoonUserFreePunish.POST("/save", public_platoon.AddFreePublishUser)
  66. }
  67. rCommunityDividends := rPublicPlatoon.Group("/communityDividends")
  68. {
  69. rCommunityDividends.POST("/communityDividendsAdd", public_platoon.AddCommunityDividends)
  70. rCommunityDividends.POST("/communityDividendsWithUserAdd", public_platoon.AddCommunityDividendsWithUser)
  71. }
  72. rUserDailyActivityAnalysis := rPublicPlatoon.Group("/userDailyActivityAnalysis")
  73. {
  74. rUserDailyActivityAnalysis.POST("", public_platoon.UserDailyActivityAnalysis)
  75. }
  76. }
  77. }
  78. func rComm(r *gin.RouterGroup) {
  79. r.POST("/getMenuList", comm.MenuList) // 获取菜单栏列表
  80. }