router.go 985 B

123456789101112131415161718192021222324252627282930
  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. )
  13. func init() {
  14. //解决跨域问题
  15. beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
  16. AllowAllOrigins: true,
  17. AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
  18. AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
  19. ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
  20. AllowCredentials: true,
  21. }))
  22. ns := beego.NewNamespace("/admin",
  23. beego.NSNamespace("/sysuser",
  24. ),
  25. )
  26. beego.AddNamespace(ns)
  27. }