router.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/product"
  7. "eta/eta_mini_ht_api/controllers/report"
  8. "eta/eta_mini_ht_api/controllers/sys"
  9. "eta/eta_mini_ht_api/controllers/user"
  10. "eta/eta_mini_ht_api/controllers/web_hook"
  11. "eta/eta_mini_ht_api/middleware"
  12. "github.com/beego/beego/v2/server/web"
  13. "github.com/beego/beego/v2/server/web/filter/cors"
  14. "time"
  15. )
  16. func init() {
  17. web.InsertFilter("*", web.BeforeRouter, cors.Allow(&cors.Options{
  18. AllowAllOrigins: true, // 允许所有来源的请求
  19. AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
  20. AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
  21. ExposeHeaders: []string{"Content-Length"},
  22. AllowCredentials: true,
  23. MaxAge: 12 * time.Hour,
  24. }))
  25. //增加授权拦截
  26. web.InsertFilter("*", web.BeforeRouter, middleware.AuthMiddleware())
  27. web.InsertFilter("/htapi/webhook/*", web.BeforeRouter, middleware.WebHookAuthMiddleware())
  28. ns := web.NewNamespace("/htapi",
  29. web.NSNamespace("/user",
  30. web.NSInclude(
  31. &user.UserController{},
  32. &user.SubscribeController{},
  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. ),
  64. ),
  65. web.NSNamespace("/product",
  66. web.NSInclude(
  67. &product.ProductController{},
  68. ),
  69. ),
  70. web.NSNamespace("/order",
  71. web.NSInclude(
  72. &order.OrderController{},
  73. ),
  74. ),
  75. web.NSNamespace("/ws",
  76. web.NSInclude(
  77. &controllers.WebSocketController{},
  78. ),
  79. ),
  80. web.NSNamespace("/system",
  81. web.NSInclude(
  82. &sys.SysController{},
  83. ),
  84. ),
  85. )
  86. web.AddNamespace(ns)
  87. }