router.go 2.5 KB

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