router.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package routers
  2. import (
  3. "eta/eta_mini_ht_api/controllers"
  4. "eta/eta_mini_ht_api/controllers/chart"
  5. "eta/eta_mini_ht_api/controllers/home"
  6. "eta/eta_mini_ht_api/controllers/media"
  7. "eta/eta_mini_ht_api/controllers/order"
  8. "eta/eta_mini_ht_api/controllers/payment"
  9. "eta/eta_mini_ht_api/controllers/product"
  10. "eta/eta_mini_ht_api/controllers/report"
  11. "eta/eta_mini_ht_api/controllers/sys"
  12. "eta/eta_mini_ht_api/controllers/user"
  13. "eta/eta_mini_ht_api/controllers/web_hook"
  14. "eta/eta_mini_ht_api/middleware"
  15. "github.com/beego/beego/v2/server/web"
  16. "github.com/beego/beego/v2/server/web/filter/cors"
  17. "time"
  18. )
  19. func init() {
  20. web.InsertFilter("*", web.BeforeRouter, cors.Allow(&cors.Options{
  21. AllowAllOrigins: true, // 允许所有来源的请求
  22. AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
  23. AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
  24. ExposeHeaders: []string{"Content-Length"},
  25. AllowCredentials: true,
  26. MaxAge: 12 * time.Hour,
  27. }))
  28. //增加授权拦截
  29. web.InsertFilter("*", web.BeforeRouter, middleware.AuthMiddleware())
  30. web.InsertFilter("/htapi/webhook/*", web.BeforeRouter, middleware.WebHookAuthMiddleware())
  31. ns := web.NewNamespace("/htapi",
  32. web.NSNamespace("/user",
  33. web.NSInclude(
  34. &user.UserController{},
  35. &user.BookMarkController{},
  36. ),
  37. ),
  38. web.NSNamespace("/home",
  39. web.NSInclude(
  40. &home.HomeController{},
  41. ),
  42. ),
  43. web.NSNamespace("/auth",
  44. web.NSInclude(
  45. &user.AuthController{},
  46. ),
  47. ),
  48. web.NSNamespace("/account",
  49. web.NSInclude(
  50. &user.AccountController{},
  51. ),
  52. ),
  53. web.NSNamespace("/report",
  54. web.NSInclude(
  55. &report.ReportController{},
  56. ),
  57. ),
  58. web.NSNamespace("/media",
  59. web.NSInclude(
  60. &media.MediaController{},
  61. ),
  62. ),
  63. web.NSNamespace("/analyst",
  64. web.NSInclude(
  65. &user.AnalystController{},
  66. ),
  67. ),
  68. web.NSNamespace("/webhook ",
  69. web.NSInclude(
  70. &web_hook.HTFuturesAccountController{},
  71. &web_hook.HTFuturesTradeController{},
  72. &web_hook.ESController{},
  73. ),
  74. ),
  75. web.NSNamespace("/product",
  76. web.NSInclude(
  77. &product.ProductController{},
  78. ),
  79. ),
  80. web.NSNamespace("/order",
  81. web.NSInclude(
  82. &order.OrderController{},
  83. &order.SubscribeController{},
  84. ),
  85. ),
  86. web.NSNamespace("/ws",
  87. web.NSInclude(
  88. &controllers.WebSocketController{},
  89. ),
  90. ),
  91. web.NSNamespace("/system",
  92. web.NSInclude(
  93. &sys.SysController{},
  94. ),
  95. ),
  96. web.NSNamespace("/payment",
  97. web.NSInclude(
  98. &payment.PaymentController{},
  99. ),
  100. ),
  101. web.NSNamespace("/chart",
  102. web.NSInclude(
  103. &chart.ChartController{},
  104. ),
  105. ),
  106. )
  107. web.AddNamespace(ns)
  108. }