beegoinit/routers/router.go
2020-07-02 15:59:04 +08:00

36 lines
656 B
Go

package router
import (
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
)
var ns = make(chan *beego.Namespace)
func init() {
go func() {
for i := range ns {
beego.AddNamespace(i)
}
}()
}
func ErrorController(c beego.ControllerInterface) {
beego.ErrorController(c)
}
func AddController(name string, c ...beego.ControllerInterface) {
linkers := make([]beego.LinkNamespace, 0)
for _, v := range c {
linkers = append(linkers, beego.NSAutoRouter(v))
}
nns := beego.NewNamespace(name, linkers...)
ns <- nns
if err := beego.AddViewPath(fmt.Sprintf("applications/%s/views/", name)); err != nil {
logs.Error(err)
}
}