router.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/astaxie/beego"
  11. "github.com/astaxie/beego/plugins/cors"
  12. "hongze/hongze_api/controllers"
  13. )
  14. func init() {
  15. //解决跨域问题
  16. beego.InsertFilter("*", beego.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 := beego.NewNamespace("/api",
  24. beego.NSNamespace("/home",
  25. beego.NSInclude(
  26. &controllers.HomeController{},
  27. ),
  28. ),
  29. beego.NSNamespace("/report",
  30. beego.NSInclude(
  31. &controllers.ReportController{},
  32. ),
  33. beego.NSInclude(
  34. &controllers.ReportShareController{},
  35. ),
  36. ),
  37. beego.NSNamespace("/classify",
  38. beego.NSInclude(
  39. &controllers.ClassifyController{},
  40. ),
  41. ),
  42. beego.NSNamespace("/wechat",
  43. beego.NSInclude(
  44. &controllers.WechatController{},
  45. ),
  46. beego.NSInclude(
  47. &controllers.WechatCommonController{},
  48. ),
  49. ),
  50. beego.NSNamespace("/user",
  51. beego.NSInclude(
  52. &controllers.UserController{},
  53. ),
  54. beego.NSInclude(
  55. &controllers.UserCommonController{},
  56. ),
  57. ),
  58. beego.NSNamespace("/video",
  59. beego.NSInclude(
  60. &controllers.VideoController{},
  61. ),
  62. ),
  63. )
  64. beego.AddNamespace(ns)
  65. }