1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 19:50:55 +00:00

simplify replacement of the base (root) tree

This commit is contained in:
Silviu Capota-Mera 2017-10-07 12:14:28 -04:00 committed by GitHub
parent 5697c6d7cc
commit fd733f76f0

18
app.go
View File

@ -225,7 +225,7 @@ func UnregisterFixedRoute(fixedRoute string, method string) *App {
continue
}
if BeeApp.Handlers.routers[m].prefix == strings.Trim(fixedRoute, "/ ") {
delete(BeeApp.Handlers.routers, m)
findAndRemoveSingleTree(BeeApp.Handlers.routers[m])
return BeeApp
}
findAndRemoveTree(subPaths, BeeApp.Handlers.routers[m], m)
@ -236,7 +236,7 @@ func UnregisterFixedRoute(fixedRoute string, method string) *App {
um := strings.ToUpper(method)
if _, ok := BeeApp.Handlers.routers[um]; ok {
if BeeApp.Handlers.routers[um].prefix == strings.Trim(fixedRoute, "/ ") {
delete(BeeApp.Handlers.routers, um)
findAndRemoveSingleTree(BeeApp.Handlers.routers[um])
return BeeApp
}
findAndRemoveTree(subPaths, BeeApp.Handlers.routers[um], um)
@ -272,6 +272,20 @@ func findAndRemoveTree(paths []string, entryPointTree *Tree, method string) {
}
}
func findAndRemoveSingleTree(entryPointTree *Tree) {
if len(entryPointTree.fixrouters) > 0 {
// Remove the *Tree from the fixrouters slice
entryPointTree.fixrouters[0] = nil
entryPointTree.fixrouters = entryPointTree.fixrouters[1:]
}
if len(entryPointTree.leaves) > 0 {
entryPointTree.leaves[0] = nil
entryPointTree.leaves = entryPointTree.leaves[1:]
}
}
// Include will generate router file in the router/xxx.go from the controller's comments
// usage:
// beego.Include(&BankAccount{}, &OrderController{},&RefundController{},&ReceiptController{})