mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 23:20:54 +00:00
commit
67fbafb380
9
tree.go
9
tree.go
@ -265,15 +265,14 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string,
|
|||||||
}
|
}
|
||||||
t.wildcard.addseg(segments[1:], route, append(wildcards, params...), reg+regexpStr)
|
t.wildcard.addseg(segments[1:], route, append(wildcards, params...), reg+regexpStr)
|
||||||
} else {
|
} else {
|
||||||
var ok bool
|
|
||||||
var subTree *Tree
|
var subTree *Tree
|
||||||
for _, subTree = range t.fixrouters {
|
for _, sub := range t.fixrouters {
|
||||||
if t.prefix == seg {
|
if sub.prefix == seg {
|
||||||
ok = true
|
subTree = sub
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !ok {
|
if subTree == nil {
|
||||||
subTree = NewTree()
|
subTree = NewTree()
|
||||||
subTree.prefix = seg
|
subTree.prefix = seg
|
||||||
t.fixrouters = append(t.fixrouters, subTree)
|
t.fixrouters = append(t.fixrouters, subTree)
|
||||||
|
12
tree_test.go
12
tree_test.go
@ -221,6 +221,18 @@ func TestAddTree4(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test for issue #1595
|
||||||
|
func TestAddTree5(t *testing.T) {
|
||||||
|
tr := NewTree()
|
||||||
|
tr.AddRouter("/v1/shop/:id", "shopdetail")
|
||||||
|
tr.AddRouter("/v1/shop/", "shophome")
|
||||||
|
ctx := context.NewContext()
|
||||||
|
obj := tr.Match("/v1/shop/", ctx)
|
||||||
|
if obj == nil || obj.(string) != "shophome" {
|
||||||
|
t.Fatal("url /v1/shop/ need match router /v1/shop/ ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSplitPath(t *testing.T) {
|
func TestSplitPath(t *testing.T) {
|
||||||
a := splitPath("")
|
a := splitPath("")
|
||||||
if len(a) != 0 {
|
if len(a) != 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user