summaryrefslogtreecommitdiff
path: root/vendor/github.com/gin-gonic/gin/tree.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/gin-gonic/gin/tree.go')
-rw-r--r--vendor/github.com/gin-gonic/gin/tree.go43
1 files changed, 30 insertions, 13 deletions
diff --git a/vendor/github.com/gin-gonic/gin/tree.go b/vendor/github.com/gin-gonic/gin/tree.go
index dda8f4f7b..878023d1c 100644
--- a/vendor/github.com/gin-gonic/gin/tree.go
+++ b/vendor/github.com/gin-gonic/gin/tree.go
@@ -351,7 +351,10 @@ func (n *node) insertChild(path string, fullPath string, handlers HandlersChain)
}
if len(n.path) > 0 && n.path[len(n.path)-1] == '/' {
- pathSeg := strings.SplitN(n.children[0].path, "/", 2)[0]
+ pathSeg := ""
+ if len(n.children) != 0 {
+ pathSeg = strings.SplitN(n.children[0].path, "/", 2)[0]
+ }
panic("catch-all wildcard '" + path +
"' in new path '" + fullPath +
"' conflicts with existing path segment '" + pathSeg +
@@ -478,7 +481,7 @@ walk: // Outer loop for walking the tree
// We can recommend to redirect to the same URL without a
// trailing slash if a leaf exists for that path.
value.tsr = path == "/" && n.handlers != nil
- return
+ return value
}
// Handle wildcard child, which is always at the end of the array
@@ -497,7 +500,14 @@ walk: // Outer loop for walking the tree
}
// Save param value
- if params != nil && cap(*params) > 0 {
+ if params != nil {
+ // Preallocate capacity if necessary
+ if cap(*params) < int(globalParamsCount) {
+ newParams := make(Params, len(*params), globalParamsCount)
+ copy(newParams, *params)
+ *params = newParams
+ }
+
if value.params == nil {
value.params = params
}
@@ -526,12 +536,12 @@ walk: // Outer loop for walking the tree
// ... but we can't
value.tsr = len(path) == end+1
- return
+ return value
}
if value.handlers = n.handlers; value.handlers != nil {
value.fullPath = n.fullPath
- return
+ return value
}
if len(n.children) == 1 {
// No handle found. Check if a handle for this path + a
@@ -539,11 +549,18 @@ walk: // Outer loop for walking the tree
n = n.children[0]
value.tsr = (n.path == "/" && n.handlers != nil) || (n.path == "" && n.indices == "/")
}
- return
+ return value
case catchAll:
// Save param value
if params != nil {
+ // Preallocate capacity if necessary
+ if cap(*params) < int(globalParamsCount) {
+ newParams := make(Params, len(*params), globalParamsCount)
+ copy(newParams, *params)
+ *params = newParams
+ }
+
if value.params == nil {
value.params = params
}
@@ -564,7 +581,7 @@ walk: // Outer loop for walking the tree
value.handlers = n.handlers
value.fullPath = n.fullPath
- return
+ return value
default:
panic("invalid node type")
@@ -595,7 +612,7 @@ walk: // Outer loop for walking the tree
// Check if this node has a handle registered.
if value.handlers = n.handlers; value.handlers != nil {
value.fullPath = n.fullPath
- return
+ return value
}
// If there is no handle for this route, but this route has a
@@ -603,12 +620,12 @@ walk: // Outer loop for walking the tree
// additional trailing slash
if path == "/" && n.wildChild && n.nType != root {
value.tsr = true
- return
+ return value
}
if path == "/" && n.nType == static {
value.tsr = true
- return
+ return value
}
// No handle found. Check if a handle for this path + a
@@ -618,11 +635,11 @@ walk: // Outer loop for walking the tree
n = n.children[i]
value.tsr = (len(n.path) == 1 && n.handlers != nil) ||
(n.nType == catchAll && n.children[0].handlers != nil)
- return
+ return value
}
}
- return
+ return value
}
// Nothing found. We can recommend to redirect to the same URL with an
@@ -648,7 +665,7 @@ walk: // Outer loop for walking the tree
}
}
- return
+ return value
}
}