refactor: create seperate function to handle empty tree condition

This commit is contained in:
72 2026-04-28 09:17:13 +05:00
parent d3ffc99852
commit ad38d93dbc

22
tree.go
View File

@ -130,18 +130,28 @@ func (n *node) incrementChildPrio(pos int) int {
return newPos
}
func (n *node) compareEmptyTree(path string, fullPath string, handlers HandlersChain) {
if len(n.path) == 0 && len(n.children) == 0 {
n.insertChild(path, fullPath, handlers)
n.nType = root
return
}
}
// addRoute adds a node with the given handle to the path.
// Not concurrency-safe!
func (n *node) addRoute(path string, handlers HandlersChain) {
fullPath := path
n.priority++
// Empty tree
if len(n.path) == 0 && len(n.children) == 0 {
n.insertChild(path, fullPath, handlers)
n.nType = root
return
}
// // Empty tree
// if len(n.path) == 0 && len(n.children) == 0 {
// n.insertChild(path, fullPath, handlers)
// n.nType = root
// return
// }
n.compareEmptyTree(path, fullPath, handlers)
parentFullPathIndex := 0