Skip to content

Commit

Permalink
Fix subrouter matching, match inner node path part based on type
Browse files Browse the repository at this point in the history
  • Loading branch information
vardius committed Oct 20, 2019
1 parent 377c2c1 commit 5a3de5a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions mux/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,27 @@ type subrouterNode struct {
Node
}

func (n *subrouterNode) Match(path string) (Node, context.Params, string) {
switch node := n.Node.(type) {
case *staticNode:
return node.Match(path[:len(node.name)])
case *wildcardNode:
pathPart, subPath := pathutils.GetPart(path)
n, params, _ := node.Match(pathPart)

return n, params, subPath
case *regexpNode:
pathPart, subPath := pathutils.GetPart(path)
n, params, _ := node.Match(pathPart)

return n, params, subPath
case *subrouterNode:
return node.Match(path)
}

return nil, nil, ""
}

func (n *subrouterNode) WithChildren(t Tree) {
panic("Subrouter node can not have children.")
}

0 comments on commit 5a3de5a

Please sign in to comment.