|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package router
-
- import (
- "applet/app/cfg"
- "applet/app/hdl"
- "applet/app/hdl/comm"
- "applet/app/hdl/institutional_management/egg_energy"
- "applet/app/hdl/institutional_management/public_platoon"
- "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)
- })
-
- // 是否打印访问日志, 在非正式环境都打印
- if mode != "release" {
- r.Use(gin.Logger())
- }
- r.Use(gin.Recovery())
-
- 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("/login", hdl.Login)
- r.Use(mw.Auth) // 以下接口需要JWT验证
- rComm(r.Group("/comm"))
- r.Use(mw.CheckPermission) // 检测权限
- rInstitutionalManagement(r.Group("/institutionalManagement"))
- }
-
- func rInstitutionalManagement(r *gin.RouterGroup) { //制度管理
- rPublicPlatoon := r.Group("/publicPlatoon") //公排设置
- {
- rPublicPlatoon.GET("/getBasic", public_platoon.GetPublicPlatoonBasic)
- rPublicPlatoon.PUT("/updateBasic", public_platoon.UpdatePublicPlatoonBasic)
- rPublicPlatoon.GET("/relationshipMap", public_platoon.GetRelationshipMap)
- rPublicPlatoon.GET("/findUserRelationshipMap", public_platoon.FindUserRelationshipMap)
- rPublicPlatoon.GET("/findSubUserRelationshipMap", public_platoon.FindSubUserRelationshipMap)
- rPublicPlatoon.POST("/exchangeUserPosition", public_platoon.ExchangeUserPosition)
- rPublicPlatoonUserFreePunish := rPublicPlatoon.Group("/publicPlatoonUserFreePunish")
- {
- rPublicPlatoonUserFreePunish.POST("/index", public_platoon.GetFreePublishUser)
- rPublicPlatoonUserFreePunish.POST("/save", public_platoon.AddFreePublishUser)
- }
- rCommunityDividends := rPublicPlatoon.Group("/communityDividends")
- {
- rCommunityDividends.POST("/communityDividendsList", public_platoon.ListCommunityDividends)
- rCommunityDividends.POST("/communityDividendsAdd", public_platoon.AddCommunityDividends)
- rCommunityDividends.POST("/communityDividendsWithUserList", public_platoon.ListCommunityDividendsWithUser)
- rCommunityDividends.POST("/communityDividendsWithUserAdd", public_platoon.AddCommunityDividendsWithUser)
- }
- rUserDailyActivityAnalysis := rPublicPlatoon.Group("/userDailyActivityAnalysis")
- {
- rUserDailyActivityAnalysis.POST("/index", public_platoon.UserDailyActivityAnalysis)
- }
-
- }
- rEggEnergy := r.Group("/eggEnergy")
- {
- rEggEnergy.GET("/getBasic", egg_energy.GetEggEnergyBasic)
- rEggEnergy.POST("/updateBasic", egg_energy.UpdateEggEnergyBasic)
- rEggEnergyUserCoin := rEggEnergy.Group("/userCoin")
- {
- rEggEnergyUserCoin.POST("/activePointsUserCoinList", egg_energy.GetActivePointsUserCoinList)
- rEggEnergyUserCoin.POST("/activePointsUserCoinFlowList", egg_energy.GetActivePointsUserCoinFlowList)
- rEggEnergyUserCoin.POST("/greenEnergyUserCoinList", egg_energy.GetGreenEnergyUserCoinList)
- rEggEnergyUserCoin.POST("/greenEnergyUserCoinFlowList", egg_energy.GetGreenEnergyUserCoinFlowList)
- }
- rEggEnergyAvailableEnergy := rPublicPlatoon.Group("/availableEnergy")
- {
- rEggEnergyAvailableEnergy.POST("/list", egg_energy.DynamicDataFlowList)
- }
- }
- }
-
- func rComm(r *gin.RouterGroup) {
- r.POST("/getMenuList", comm.MenuList) // 获取菜单栏列表
- }
|