Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2020-05-07 15:29:28 +08:00
parent e952fe3517
commit ac41b9b486
2 changed files with 16 additions and 16 deletions

4
gin.go
View File

@ -259,7 +259,7 @@ func (engine *Engine) addRoute(method, path string, handlers HandlersChain) {
root := engine.trees.get(method) root := engine.trees.get(method)
if root == nil { if root == nil {
root = new(node) root = new(node)
root.fullPath = "/" // root.fullPath = "/"
engine.trees = append(engine.trees, methodTree{method: method, root: root}) engine.trees = append(engine.trees, methodTree{method: method, root: root})
} }
root.addRoute(path, handlers) root.addRoute(path, handlers)
@ -406,7 +406,7 @@ func (engine *Engine) handleHTTPRequest(c *Context) {
if value.handlers != nil { if value.handlers != nil {
c.handlers = value.handlers c.handlers = value.handlers
c.Params = value.params c.Params = value.params
c.fullPath = value.fullPath // c.fullPath = value.fullPath
c.Next() c.Next()
c.writermem.WriteHeaderNow() c.writermem.WriteHeaderNow()
return return

28
tree.go
View File

@ -103,7 +103,7 @@ type node struct {
nType nodeType nType nodeType
maxParams uint8 maxParams uint8
wildChild bool wildChild bool
fullPath string // fullPath string
} }
// increments priority of the given child and reorders if necessary. // increments priority of the given child and reorders if necessary.
@ -166,7 +166,7 @@ walk:
children: n.children, children: n.children,
handlers: n.handlers, handlers: n.handlers,
priority: n.priority - 1, priority: n.priority - 1,
fullPath: n.fullPath, // fullPath: n.fullPath,
} }
// Update maxParams (max of all children) // Update maxParams (max of all children)
@ -182,7 +182,7 @@ walk:
n.path = path[:i] n.path = path[:i]
n.handlers = nil n.handlers = nil
n.wildChild = false n.wildChild = false
n.fullPath = fullPath[:parentFullPathIndex+i] // n.fullPath = fullPath[:parentFullPathIndex+i]
} }
// Make new node a child of this node // Make new node a child of this node
@ -246,7 +246,7 @@ walk:
n.indices += string([]byte{c}) n.indices += string([]byte{c})
child := &node{ child := &node{
maxParams: numParams, maxParams: numParams,
fullPath: fullPath, // fullPath: fullPath,
} }
n.children = append(n.children, child) n.children = append(n.children, child)
n.incrementChildPrio(len(n.indices) - 1) n.incrementChildPrio(len(n.indices) - 1)
@ -328,7 +328,7 @@ func (n *node) insertChild(numParams uint8, path string, fullPath string, handle
nType: param, nType: param,
path: wildcard, path: wildcard,
maxParams: numParams, maxParams: numParams,
fullPath: fullPath, // fullPath: fullPath,
} }
n.children = []*node{child} n.children = []*node{child}
n = child n = child
@ -343,7 +343,7 @@ func (n *node) insertChild(numParams uint8, path string, fullPath string, handle
child := &node{ child := &node{
maxParams: numParams, maxParams: numParams,
priority: 1, priority: 1,
fullPath: fullPath, // fullPath: fullPath,
} }
n.children = []*node{child} n.children = []*node{child}
n = child n = child
@ -377,7 +377,7 @@ func (n *node) insertChild(numParams uint8, path string, fullPath string, handle
wildChild: true, wildChild: true,
nType: catchAll, nType: catchAll,
maxParams: 1, maxParams: 1,
fullPath: fullPath, // fullPath: fullPath,
} }
// update maxParams of the parent node // update maxParams of the parent node
if n.maxParams < 1 { if n.maxParams < 1 {
@ -392,10 +392,10 @@ func (n *node) insertChild(numParams uint8, path string, fullPath string, handle
child = &node{ child = &node{
path: path[i:], path: path[i:],
nType: catchAll, nType: catchAll,
maxParams: 1,
handlers: handlers, handlers: handlers,
priority: 1, priority: 1,
fullPath: fullPath, maxParams: 1,
// fullPath: fullPath,
} }
n.children = []*node{child} n.children = []*node{child}
@ -405,7 +405,7 @@ func (n *node) insertChild(numParams uint8, path string, fullPath string, handle
// If no wildcard was found, simply insert the path and handle // If no wildcard was found, simply insert the path and handle
n.path = path n.path = path
n.handlers = handlers n.handlers = handlers
n.fullPath = fullPath // n.fullPath = fullPath
} }
// nodeValue holds return values of (*Node).getValue method // nodeValue holds return values of (*Node).getValue method
@ -413,7 +413,7 @@ type nodeValue struct {
handlers HandlersChain handlers HandlersChain
params Params params Params
tsr bool tsr bool
fullPath string // fullPath string
} }
// getValue returns the handle registered with the given path (key). The values of // getValue returns the handle registered with the given path (key). The values of
@ -430,7 +430,7 @@ walk: // Outer loop for walking the tree
// We should have reached the node containing the handle. // We should have reached the node containing the handle.
// Check if this node has a handle registered. // Check if this node has a handle registered.
if value.handlers = n.handlers; value.handlers != nil { if value.handlers = n.handlers; value.handlers != nil {
value.fullPath = n.fullPath // value.fullPath = n.fullPath
return return
} }
@ -519,7 +519,7 @@ walk: // Outer loop for walking the tree
} }
if value.handlers = n.handlers; value.handlers != nil { if value.handlers = n.handlers; value.handlers != nil {
value.fullPath = n.fullPath // value.fullPath = n.fullPath
return return
} }
if len(n.children) == 1 { if len(n.children) == 1 {
@ -548,7 +548,7 @@ walk: // Outer loop for walking the tree
} }
value.handlers = n.handlers value.handlers = n.handlers
value.fullPath = n.fullPath // value.fullPath = n.fullPath
return return
default: default: