router.go 2.3 KB

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