智盟项目
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.0 KiB

  1. package router
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/hdl"
  5. internalHdl "applet/app/hdl/zhimeng_internal"
  6. platformHdl "applet/app/hdl/zhimeng_platform"
  7. "applet/app/mw"
  8. "github.com/gin-gonic/gin"
  9. )
  10. //初始化路由
  11. func Init() *gin.Engine {
  12. // debug, release, test 项目阶段
  13. mode := "release"
  14. if cfg.Debug {
  15. mode = "debug"
  16. }
  17. gin.SetMode(mode)
  18. //创建一个新的启动器
  19. r := gin.New()
  20. r.Use(mw.ChangeHeader)
  21. // 是否打印访问日志, 在非正式环境都打印
  22. if mode != "release" {
  23. r.Use(gin.Logger())
  24. }
  25. r.Use(gin.Recovery())
  26. // r.Use(mw.Limiter)
  27. //r.LoadHTMLGlob("static/html/*")
  28. r.GET("/favicon.ico", func(c *gin.Context) {
  29. c.Status(204)
  30. })
  31. r.NoRoute(func(c *gin.Context) {
  32. c.JSON(404, gin.H{"code": 404, "msg": "page not found", "data": []struct{}{}})
  33. })
  34. r.NoMethod(func(c *gin.Context) {
  35. c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}})
  36. })
  37. r.Use(mw.Cors)
  38. routeInternal(r.Group("/api/internal"))
  39. routeZhimeng(r.Group("/api/admin"))
  40. return r
  41. }
  42. func routeInternal(r *gin.RouterGroup) {
  43. r.Use(mw.DB) // 以下接口需要用到数据库
  44. {
  45. r.POST("/playlet_order", internalHdl.GetPlayletOrder)
  46. }
  47. r.Use(mw.Checker) // 以下接口需要检查Header: platform
  48. {
  49. }
  50. r.Use(mw.Auth) // 以下接口需要JWT验证
  51. {
  52. }
  53. }
  54. func routeZhimeng(r *gin.RouterGroup) {
  55. r.GET("/authorizationCode", hdl.GetAuthorizationCode)
  56. r.GET("/token", hdl.GetToken)
  57. r.POST("/rToken", hdl.RefreshToken)
  58. r.Use(mw.AuthJWT, mw.RequestCache) // 以下接口需要JWT验证
  59. {
  60. r.POST("/order_list", platformHdl.OrderList)
  61. r.POST("/order_output", platformHdl.OrderOutput)
  62. r.POST("/withdrawal_income", platformHdl.WithdrawalIncome)
  63. r.POST("/withdrawal_bind_alipay", platformHdl.WithdrawalBindAlipay)
  64. r.POST("/withdrawal_list", platformHdl.WithdrawalList)
  65. r.POST("/withdrawal_doing", platformHdl.WithdrawalDoing)
  66. r.POST("/withdrawal_output", platformHdl.WithdrawalOutput)
  67. r.POST("/withdrawal_invoice_img", platformHdl.WithdrawalInvoiceImg)
  68. }
  69. }