mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
router: minor improvement
This commit is contained in:
parent
3d99983d96
commit
070a81d38f
|
@ -127,24 +127,22 @@ func (tr *trie) insert(path string, route context.RouteReadOnly, handlers contex
|
||||||
|
|
||||||
var paramKeys []string
|
var paramKeys []string
|
||||||
|
|
||||||
for _, s := range input {
|
for i, s := range input {
|
||||||
if len(s) == 0 {
|
if len(s) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
c := s[0]
|
c := s[0]
|
||||||
|
|
||||||
if isParam, isWildcard := c == paramStartCharacter, c == wildcardParamStartCharacter; isParam || isWildcard {
|
if len(s)-1 > i+1 && s[i+1] != '/' { // has next character and it's not slash.
|
||||||
n.hasDynamicChild = true
|
// get the next character, if not slash then this is a parameter.
|
||||||
paramKeys = append(paramKeys, s[1:]) // without : or *.
|
// E.g:
|
||||||
|
// If /test/:param (or /test/*param) then it's dynamic.
|
||||||
// if node has already a wildcard, don't force a value, check for true only.
|
// If /test/: (or /test/*) then it's static.
|
||||||
if isParam {
|
if c == paramStartCharacter {
|
||||||
n.childNamedParameter = true
|
n.childNamedParameter = true
|
||||||
s = ParamStart
|
s = ParamStart
|
||||||
}
|
} else if c == wildcardParamStartCharacter {
|
||||||
|
|
||||||
if isWildcard {
|
|
||||||
n.childWildcardParameter = true
|
n.childWildcardParameter = true
|
||||||
s = WildcardParamStart
|
s = WildcardParamStart
|
||||||
if tr.root == n {
|
if tr.root == n {
|
||||||
|
@ -205,16 +203,6 @@ func (tr *trie) search(q string, params *context.RequestParams) *trieNode {
|
||||||
segment := q[start:i]
|
segment := q[start:i]
|
||||||
if child := n.getChild(segment); child != nil {
|
if child := n.getChild(segment); child != nil {
|
||||||
n = child
|
n = child
|
||||||
// Possible reserved param character, should catch it as
|
|
||||||
// dynamic node instead of static-path based.
|
|
||||||
if segment == ParamStart { // len(n.paramKeys) > 0 && (segment == ParamStart || segment == WildcardParamStart)
|
|
||||||
if ln := len(paramValues); cap(paramValues) > ln {
|
|
||||||
paramValues = paramValues[:ln+1]
|
|
||||||
paramValues[ln] = segment
|
|
||||||
} else {
|
|
||||||
paramValues = append(paramValues, segment)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if n.childNamedParameter {
|
} else if n.childNamedParameter {
|
||||||
n = n.getChild(ParamStart)
|
n = n.getChild(ParamStart)
|
||||||
if ln := len(paramValues); cap(paramValues) > ln {
|
if ln := len(paramValues); cap(paramValues) > ln {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user