Skip to content

Commit 0603e23

Browse files
committed
refactor: refactor return logic in tree operations
- Modify multiple return statements in `tree.go` to return a specific value instead of nothing Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent befcf6f commit 0603e23

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

tree.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ walk: // Outer loop for walking the tree
478478
// We can recommend to redirect to the same URL without a
479479
// trailing slash if a leaf exists for that path.
480480
value.tsr = path == "/" && n.handlers != nil
481-
return
481+
return value
482482
}
483483

484484
// Handle wildcard child, which is always at the end of the array
@@ -533,20 +533,20 @@ walk: // Outer loop for walking the tree
533533

534534
// ... but we can't
535535
value.tsr = len(path) == end+1
536-
return
536+
return value
537537
}
538538

539539
if value.handlers = n.handlers; value.handlers != nil {
540540
value.fullPath = n.fullPath
541-
return
541+
return value
542542
}
543543
if len(n.children) == 1 {
544544
// No handle found. Check if a handle for this path + a
545545
// trailing slash exists for TSR recommendation
546546
n = n.children[0]
547547
value.tsr = (n.path == "/" && n.handlers != nil) || (n.path == "" && n.indices == "/")
548548
}
549-
return
549+
return value
550550

551551
case catchAll:
552552
// Save param value
@@ -578,7 +578,7 @@ walk: // Outer loop for walking the tree
578578

579579
value.handlers = n.handlers
580580
value.fullPath = n.fullPath
581-
return
581+
return value
582582

583583
default:
584584
panic("invalid node type")
@@ -609,20 +609,20 @@ walk: // Outer loop for walking the tree
609609
// Check if this node has a handle registered.
610610
if value.handlers = n.handlers; value.handlers != nil {
611611
value.fullPath = n.fullPath
612-
return
612+
return value
613613
}
614614

615615
// If there is no handle for this route, but this route has a
616616
// wildcard child, there must be a handle for this path with an
617617
// additional trailing slash
618618
if path == "/" && n.wildChild && n.nType != root {
619619
value.tsr = true
620-
return
620+
return value
621621
}
622622

623623
if path == "/" && n.nType == static {
624624
value.tsr = true
625-
return
625+
return value
626626
}
627627

628628
// No handle found. Check if a handle for this path + a
@@ -632,11 +632,11 @@ walk: // Outer loop for walking the tree
632632
n = n.children[i]
633633
value.tsr = (len(n.path) == 1 && n.handlers != nil) ||
634634
(n.nType == catchAll && n.children[0].handlers != nil)
635-
return
635+
return value
636636
}
637637
}
638638

639-
return
639+
return value
640640
}
641641

642642
// Nothing found. We can recommend to redirect to the same URL with an
@@ -662,7 +662,7 @@ walk: // Outer loop for walking the tree
662662
}
663663
}
664664

665-
return
665+
return value
666666
}
667667
}
668668

0 commit comments

Comments
 (0)