diff options
author | Wim <wim@42.be> | 2020-01-09 21:02:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-09 21:02:56 +0100 |
commit | 0f708daf2d14dcca261ef98cc698a1b1f2a6aa74 (patch) | |
tree | 022eee21366d6a9a00feaeff918972d9e72632c2 /vendor/github.com/labstack/echo/v4/router.go | |
parent | b9354de8fd5e424ac2f246fff1a03b27e8094fd8 (diff) | |
download | matterbridge-msglm-0f708daf2d14dcca261ef98cc698a1b1f2a6aa74.tar.gz matterbridge-msglm-0f708daf2d14dcca261ef98cc698a1b1f2a6aa74.tar.bz2 matterbridge-msglm-0f708daf2d14dcca261ef98cc698a1b1f2a6aa74.zip |
Update dependencies (#975)
Diffstat (limited to 'vendor/github.com/labstack/echo/v4/router.go')
-rw-r--r-- | vendor/github.com/labstack/echo/v4/router.go | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/vendor/github.com/labstack/echo/v4/router.go b/vendor/github.com/labstack/echo/v4/router.go index 70bf409f..08145973 100644 --- a/vendor/github.com/labstack/echo/v4/router.go +++ b/vendor/github.com/labstack/echo/v4/router.go @@ -1,6 +1,9 @@ package echo -import "net/http" +import ( + "net/http" + "strings" +) type ( // Router is the registry of all registered routes for an `Echo` instance for @@ -20,8 +23,8 @@ type ( pnames []string methodHandler *methodHandler } - kind uint8 - children []*node + kind uint8 + children []*node methodHandler struct { connect HandlerFunc delete HandlerFunc @@ -133,6 +136,11 @@ func (r *Router) insert(method, path string, h HandlerFunc, t kind, ppath string // Split node n := newNode(cn.kind, cn.prefix[l:], cn, cn.children, cn.methodHandler, cn.ppath, cn.pnames) + // Update parent path for all children to new node + for _, child := range cn.children { + child.parent = n + } + // Reset parent node cn.kind = skind cn.label = cn.prefix[0] @@ -336,7 +344,6 @@ func (r *Router) Find(method, path string, c Context) { } } - if l == pl { // Continue search search = search[l:] @@ -398,16 +405,33 @@ func (r *Router) Find(method, path string, c Context) { Any: if cn = cn.findChildByKind(akind); cn == nil { if nn != nil { - cn = nn - nn = cn.parent // Next (Issue #954) - if nn != nil { - nk = nn.kind - } + // No next node to go down in routing (issue #954) + // Find nearest "any" route going up the routing tree search = ns - if nk == pkind { - goto Param - } else if nk == akind { - goto Any + np := nn.parent + // Consider param route one level up only + // if no slash is remaining in search string + if cn = nn.findChildByKind(pkind); cn != nil && strings.IndexByte(ns, '/') == -1 { + pvalues[len(cn.pnames)-1] = search + break + } + for { + np = nn.parent + if cn = nn.findChildByKind(akind); cn != nil { + break + } + if np == nil { + break // no further parent nodes in tree, abort + } + var str strings.Builder + str.WriteString(nn.prefix) + str.WriteString(search) + search = str.String() + nn = np + } + if cn != nil { // use the found "any" route and update path + pvalues[len(cn.pnames)-1] = search + break } } return // Not found |