蛋蛋星球-客户端
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.
 
 
 
 
 
 

83 line
2.8 KiB

  1. package router
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/hdl"
  5. "applet/app/hdl/comm"
  6. "applet/app/mw"
  7. _ "applet/docs"
  8. "github.com/gin-gonic/gin"
  9. swaggerFiles "github.com/swaggo/files"
  10. ginSwagger "github.com/swaggo/gin-swagger"
  11. )
  12. // 初始化路由
  13. func Init() *gin.Engine {
  14. // debug, release, test 项目阶段
  15. mode := "release"
  16. if cfg.Debug {
  17. mode = "debug"
  18. }
  19. gin.SetMode(mode)
  20. //创建一个新的启动器
  21. r := gin.New()
  22. r.GET("/api/swagger/*any", func(c *gin.Context) {
  23. // r.Use(mw.SwagAuth())
  24. ginSwagger.DisablingWrapHandler(swaggerFiles.Handler, "SWAGGER")(c)
  25. })
  26. // 是否打印访问日志, 在非正式环境都打印
  27. if mode != "release" {
  28. r.Use(gin.Logger())
  29. }
  30. r.Use(gin.Recovery())
  31. r.GET("/favicon.ico", func(c *gin.Context) {
  32. c.Status(204)
  33. })
  34. r.NoRoute(func(c *gin.Context) {
  35. c.JSON(404, gin.H{"code": 404, "msg": "page not found", "data": []struct{}{}})
  36. })
  37. r.NoMethod(func(c *gin.Context) {
  38. c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}})
  39. })
  40. r.Use(mw.Cors)
  41. route(r.Group("/api/v1"))
  42. return r
  43. }
  44. func route(r *gin.RouterGroup) {
  45. r.GET("/test", hdl.Demo)
  46. r.Any("/createSign", hdl.CreateSign)
  47. r.Any("/aesDecryptByECB", hdl.AesDecryptByECB)
  48. r.Use(mw.CheckSign)
  49. r.Any("/testCreateSign", hdl.TestCreateSign)
  50. r.POST("/register", hdl.Register)
  51. r.POST("/login", hdl.Login)
  52. r.Use(mw.Auth) // 以下接口需要JWT验证
  53. rComm(r.Group("/comm"))
  54. rHomePage := r.Group("/homePage")
  55. {
  56. rHomePage.GET("/index", hdl.HomePage) // 主页
  57. rHomePage.GET("/adRule", hdl.HomePageWatchAdRule) // 主页-可以观看广告列表
  58. rHomePage.GET("/realTimePrice", hdl.RealTimePrice) // 主页-实时数据
  59. rHomePage.GET("/isCanSignIn", hdl.IsCanSignIn) // 主页-是否可以观看广告
  60. rHomePage.GET("/isCanGetRedPackage", hdl.IsCanGetRedPackage) // 主页-是否可以获得红包
  61. }
  62. rAddFriend := r.Group("/addFriend")
  63. {
  64. rAddFriend.POST("/eggEnergyDetails", hdl.EggEnergyDetails) // 添加好友-蛋蛋能量明细
  65. rAddFriend.POST("/eggPointDetails", hdl.EggPointDetails) // 添加好友-蛋蛋积分明细
  66. rAddFriend.GET("/basalRate", hdl.BasalRate) // 添加好友-基础速率
  67. rAddFriend.GET("/totalRate", hdl.TotalRate) // 添加好友-总速率
  68. rAddFriend.GET("/myFans", hdl.MyFans) // 添加好友-我的粉丝-团队速率
  69. rAddFriend.GET("/myFansUserList", hdl.MyFansUserList) // 添加好友-我的粉丝-好友列表
  70. rAddFriend.GET("/nineDimensionalSpace", hdl.NineDimensionalSpace) // 添加好友-我的粉丝-九维空间
  71. }
  72. }
  73. func rComm(r *gin.RouterGroup) {
  74. r.GET("/getOssUrl", comm.GetOssUrl) // 获取阿里云上传PutObject所需的签名URL
  75. }