router.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // @APIVersion 1.0.0
  2. // @Title beego Test API
  3. // @Description beego has a very cool tools to autogenerate documents for your API
  4. // @Contact astaxie@gmail.com
  5. // @TermsOfServiceUrl http://beego.me/
  6. // @License Apache 2.0
  7. // @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
  8. package routers
  9. import (
  10. "github.com/beego/beego/v2/server/web"
  11. "github.com/beego/beego/v2/server/web/filter/cors"
  12. "hongze/hongze_api/controllers"
  13. )
  14. func init() {
  15. //解决跨域问题
  16. web.InsertFilter("*", web.BeforeRouter, cors.Allow(&cors.Options{
  17. AllowAllOrigins: true,
  18. AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
  19. AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
  20. ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
  21. AllowCredentials: true,
  22. }))
  23. ns := web.NewNamespace("/api",
  24. web.NSNamespace("/home",
  25. web.NSInclude(
  26. &controllers.HomeController{},
  27. ),
  28. web.NSInclude(
  29. &controllers.HomeCommonController{},
  30. ),
  31. ),
  32. web.NSNamespace("/report",
  33. web.NSInclude(
  34. &controllers.ReportController{},
  35. ),
  36. web.NSInclude(
  37. &controllers.ReportShareController{},
  38. ),
  39. web.NSInclude(
  40. &controllers.ReportCommonController{},
  41. ),
  42. ),
  43. web.NSNamespace("/classify",
  44. web.NSInclude(
  45. &controllers.ClassifyController{},
  46. ),
  47. web.NSInclude(
  48. &controllers.ClassifyCommonController{},
  49. ),
  50. ),
  51. web.NSNamespace("/wechat",
  52. web.NSInclude(
  53. &controllers.WechatController{},
  54. ),
  55. web.NSInclude(
  56. &controllers.WechatCommonController{},
  57. ),
  58. ),
  59. web.NSNamespace("/user",
  60. web.NSInclude(
  61. &controllers.UserController{},
  62. ),
  63. web.NSInclude(
  64. &controllers.UserCommonController{},
  65. ),
  66. web.NSInclude(
  67. &controllers.UserNotAuthController{},
  68. ),
  69. web.NSInclude(
  70. &controllers.UserPcNotAuthController{},
  71. ),
  72. web.NSInclude(
  73. &controllers.YbApplyController{},
  74. ),
  75. ),
  76. web.NSNamespace("/video",
  77. web.NSInclude(
  78. &controllers.VideoController{},
  79. ),
  80. ),
  81. web.NSNamespace("/bill",
  82. web.NSInclude(
  83. &controllers.BillController{},
  84. ),
  85. ),
  86. web.NSNamespace("/runlog",
  87. web.NSInclude(
  88. &controllers.RunLogController{},
  89. ),
  90. ),
  91. web.NSNamespace("/english_report",
  92. web.NSInclude(
  93. &controllers.EnglishReportShareController{},
  94. &controllers.EnglishReportController{},
  95. ),
  96. ),
  97. )
  98. web.AddNamespace(ns)
  99. }