router.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. "spaceofcheng/services/controllers"
  11. "spaceofcheng/services/utils"
  12. "github.com/astaxie/beego"
  13. )
  14. func RouteInit() {
  15. appRoot := utils.GetAppRoot()
  16. appConf, _ := utils.GetConfiger(appRoot + "/conf/app.conf")
  17. if appConf == nil {
  18. return
  19. }
  20. prefix := appConf.String("api::prefix")
  21. guestPrefix := appConf.String("api::guest")
  22. commonPrefix := appConf.String("api::common")
  23. wechatPrefix := appConf.String("api::wechat")
  24. ns := beego.NewNamespace(prefix,
  25. // 解决跨域时 先发送 options 问题
  26. beego.NSRouter("*", &controllers.BaseController{}, "options:Options"),
  27. // 通用需要鉴权路由
  28. getCommonRoutes(commonPrefix),
  29. // 微信路由
  30. getWechatRoutes(wechatPrefix),
  31. // 不需要鉴权的路由
  32. getGuestRoutes(guestPrefix),
  33. )
  34. beego.AddNamespace(ns)
  35. }