mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 23:12:17 +08:00
udpate
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
71f841a1f5
commit
fe436bf2c0
5
gin.go
5
gin.go
@ -253,6 +253,7 @@ func (engine *Engine) rebuild405Handlers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) addRoute(method, path string, handlers HandlersChain) {
|
func (engine *Engine) addRoute(method, path string, handlers HandlersChain) {
|
||||||
|
// log.Println(method, path)
|
||||||
assert1(path[0] == '/', "path must begin with '/'")
|
assert1(path[0] == '/', "path must begin with '/'")
|
||||||
assert1(method != "", "HTTP method can not be empty")
|
assert1(method != "", "HTTP method can not be empty")
|
||||||
assert1(len(handlers) > 0, "there must be at least one handler")
|
assert1(len(handlers) > 0, "there must be at least one handler")
|
||||||
@ -269,13 +270,15 @@ func (engine *Engine) addRoute(method, path string, handlers HandlersChain) {
|
|||||||
root.addRoute(path, handlers)
|
root.addRoute(path, handlers)
|
||||||
|
|
||||||
// Update maxParams
|
// Update maxParams
|
||||||
if paramsCount := countParams(path); paramsCount+varsCount > root.maxParams {
|
// log.Println("countParams(path):", countParams(path))
|
||||||
|
if paramsCount := countParams(path); paramsCount+varsCount > engine.maxParams {
|
||||||
engine.maxParams = paramsCount + varsCount
|
engine.maxParams = paramsCount + varsCount
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lazy-init paramsPool alloc func
|
// Lazy-init paramsPool alloc func
|
||||||
if engine.paramsPool.New == nil && engine.maxParams > 0 {
|
if engine.paramsPool.New == nil && engine.maxParams > 0 {
|
||||||
engine.paramsPool.New = func() interface{} {
|
engine.paramsPool.New = func() interface{} {
|
||||||
|
// log.Println("engine.maxParams:", engine.maxParams)
|
||||||
ps := make(Params, 0, engine.maxParams)
|
ps := make(Params, 0, engine.maxParams)
|
||||||
return &ps
|
return &ps
|
||||||
}
|
}
|
||||||
|
12
tree.go
12
tree.go
@ -5,7 +5,6 @@
|
|||||||
package gin
|
package gin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
@ -424,8 +423,8 @@ func (n *node) getValue(path string, params func() *Params, unescape bool) (valu
|
|||||||
walk: // Outer loop for walking the tree
|
walk: // Outer loop for walking the tree
|
||||||
for {
|
for {
|
||||||
prefix := n.path
|
prefix := n.path
|
||||||
|
if len(path) > len(prefix) {
|
||||||
if len(path) > len(prefix) && path[:len(prefix)] == prefix {
|
if path[:len(prefix)] == prefix {
|
||||||
path = path[len(prefix):]
|
path = path[len(prefix):]
|
||||||
// If this node does not have a wildcard (param or catchAll)
|
// If this node does not have a wildcard (param or catchAll)
|
||||||
// child, we can just look up the next child node and continue
|
// child, we can just look up the next child node and continue
|
||||||
@ -478,8 +477,6 @@ walk: // Outer loop for walking the tree
|
|||||||
}
|
}
|
||||||
// Expand slice within preallocated capacity
|
// Expand slice within preallocated capacity
|
||||||
i := len(*value.params)
|
i := len(*value.params)
|
||||||
log.Println(i)
|
|
||||||
log.Println(*value.params)
|
|
||||||
*value.params = (*value.params)[:i+1]
|
*value.params = (*value.params)[:i+1]
|
||||||
// val := path[:end]
|
// val := path[:end]
|
||||||
// if unescape {
|
// if unescape {
|
||||||
@ -489,7 +486,7 @@ walk: // Outer loop for walking the tree
|
|||||||
// }
|
// }
|
||||||
(*value.params)[i] = Param{
|
(*value.params)[i] = Param{
|
||||||
Key: n.path[1:],
|
Key: n.path[1:],
|
||||||
Value: path,
|
Value: path[:end],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -562,8 +559,7 @@ walk: // Outer loop for walking the tree
|
|||||||
panic("invalid node type")
|
panic("invalid node type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if path == prefix {
|
||||||
if path == prefix {
|
|
||||||
// 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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user