Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revert and update rules
  • Loading branch information
qm012
qm012 committed Jul 2, 2021
commit 211a63445181f085e95200f28bae8476211ade26
10 changes: 7 additions & 3 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,18 @@ func (n *node) getValue(path string, params *Params, unescape bool) (value nodeV
// level 2 router:123
// level 3 router:def
var (
skippedPath = path
skippedPath string
latestNode = n // not found `level 2 router` use latestNode

// match '/' count
// matchNum < 1 && skippedPath != '/': `level 2 router` not found,the current node needs to be equal to latestNode
// matchNum >= 1: `level (2 or 3 or 4 or ...) router`: Normal handling
matchNum int // each match will accumulate
)
//if path == "/", no need to look for router
if len(path) == 1 {
matchNum = 1
}

walk: // Outer loop for walking the tree
for {
Expand Down Expand Up @@ -562,7 +566,7 @@ walk: // Outer loop for walking the tree

if path == prefix {
// level 2 router not found and latestNode.wildChild is ture
Comment thread
qm012 marked this conversation as resolved.
Resolved
if skippedPath != "/" && matchNum < 1 && latestNode.wildChild {
if matchNum < 1 && latestNode.wildChild {
n = latestNode.children[len(latestNode.children)-1]
}
// We should have reached the node containing the handle.
Expand Down Expand Up @@ -594,7 +598,7 @@ walk: // Outer loop for walking the tree
return
}

if path != "/" && strings.HasSuffix(skippedPath, path) {
if path != "/" {
path = skippedPath
n = latestNode
skippedPath = ""
Expand Down
⌂ 换网址