improve the splitPath

This commit is contained in:
astaxie 2015-12-17 21:31:44 +08:00
parent e5096be32b
commit ae52d4aa18
1 changed files with 14 additions and 2 deletions

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
}
}