diff options
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 |