1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 08:10:58 +00:00

beego:namespace sub router add url to pattern

This commit is contained in:
astaxie 2014-06-11 23:51:19 +08:00
parent e25fcffbc0
commit 00b710e168

View File

@ -198,10 +198,12 @@ func (n *Namespace) Namespace(ns ...*Namespace) *Namespace {
for _, ni := range ns {
for k, v := range ni.handlers.routers {
if t, ok := n.handlers.routers[k]; ok {
addPrefix(v, ni.prefix)
n.handlers.routers[k].AddTree(ni.prefix, v)
} else {
t = NewTree()
t.AddTree(ni.prefix, v)
addPrefix(t, ni.prefix)
n.handlers.routers[k] = t
}
}
@ -225,10 +227,12 @@ func AddNamespace(nl ...*Namespace) {
for _, n := range nl {
for k, v := range n.handlers.routers {
if t, ok := BeeApp.Handlers.routers[k]; ok {
addPrefix(v, n.prefix)
BeeApp.Handlers.routers[k].AddTree(n.prefix, v)
} else {
t = NewTree()
t.AddTree(n.prefix, v)
addPrefix(t, n.prefix)
BeeApp.Handlers.routers[k] = t
}
}
@ -245,6 +249,20 @@ func AddNamespace(nl ...*Namespace) {
}
}
func addPrefix(t *Tree, prefix string) {
for _, v := range t.fixrouters {
addPrefix(v, prefix)
}
if t.wildcard != nil {
addPrefix(t.wildcard, prefix)
}
if t.leaf != nil {
if c, ok := t.leaf.runObject.(*controllerInfo); ok {
c.pattern = prefix + c.pattern
}
}
}
// Namespace Condition
func NSCond(cond namespaceCond) innnerNamespace {
return func(ns *Namespace) {