1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 12:20:54 +00:00

improve the splitPath

This commit is contained in:
astaxie 2015-12-17 21:31:44 +08:00
parent e5096be32b
commit ae52d4aa18

16
tree.go
View File

@ -354,10 +354,22 @@ func (t *Tree) match(pattern string, wildcardValues []string, ctx *context.Conte
}
if runObject == nil {
segments := splitPath(pattern)
wildcardValues = append(wildcardValues, seg)
start, i := 0, 0
for ; i < len(pattern); i++ {
if pattern[i] == '/' {
if i != 0 && start < len(pattern) {
wildcardValues = append(wildcardValues, pattern[start:i])
}
start = i + 1
continue
}
}
if start > 0 {
wildcardValues = append(wildcardValues, pattern[start:i])
}
for _, l := range t.leaves {
if ok := l.match(append(wildcardValues, segments...), ctx); ok {
if ok := l.match(wildcardValues, ctx); ok {
return l.runObject
}
}