mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 06:00:55 +00:00
improve the splitPath
This commit is contained in:
parent
e5096be32b
commit
ae52d4aa18
16
tree.go
16
tree.go
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user