统一初始beego mvc 的方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
656 B

  1. package router
  2. import (
  3. "fmt"
  4. "github.com/astaxie/beego"
  5. "github.com/astaxie/beego/logs"
  6. )
  7. var ns = make(chan *beego.Namespace)
  8. func init() {
  9. go func() {
  10. for i := range ns {
  11. beego.AddNamespace(i)
  12. }
  13. }()
  14. }
  15. func ErrorController(c beego.ControllerInterface) {
  16. beego.ErrorController(c)
  17. }
  18. func AddController(name string, c ...beego.ControllerInterface) {
  19. linkers := make([]beego.LinkNamespace, 0)
  20. for _, v := range c {
  21. linkers = append(linkers, beego.NSAutoRouter(v))
  22. }
  23. nns := beego.NewNamespace(name, linkers...)
  24. ns <- nns
  25. if err := beego.AddViewPath(fmt.Sprintf("applications/%s/views/", name)); err != nil {
  26. logs.Error(err)
  27. }
  28. }