增加websocket支持

This commit is contained in:
2025-09-08 13:47:13 +08:00
parent 9caedd697d
commit 7e0fd53dd3
336 changed files with 9020 additions and 20356 deletions

View File

@@ -351,10 +351,7 @@ func (n *node) insertChild(path string, fullPath string, handlers HandlersChain)
}
if len(n.path) > 0 && n.path[len(n.path)-1] == '/' {
pathSeg := ""
if len(n.children) != 0 {
pathSeg = strings.SplitN(n.children[0].path, "/", 2)[0]
}
pathSeg := strings.SplitN(n.children[0].path, "/", 2)[0]
panic("catch-all wildcard '" + path +
"' in new path '" + fullPath +
"' conflicts with existing path segment '" + pathSeg +
@@ -481,7 +478,7 @@ walk: // Outer loop for walking the tree
// We can recommend to redirect to the same URL without a
// trailing slash if a leaf exists for that path.
value.tsr = path == "/" && n.handlers != nil
return value
return
}
// Handle wildcard child, which is always at the end of the array
@@ -500,14 +497,7 @@ walk: // Outer loop for walking the tree
}
// Save param value
if params != nil {
// Preallocate capacity if necessary
if cap(*params) < int(globalParamsCount) {
newParams := make(Params, len(*params), globalParamsCount)
copy(newParams, *params)
*params = newParams
}
if params != nil && cap(*params) > 0 {
if value.params == nil {
value.params = params
}
@@ -536,12 +526,12 @@ walk: // Outer loop for walking the tree
// ... but we can't
value.tsr = len(path) == end+1
return value
return
}
if value.handlers = n.handlers; value.handlers != nil {
value.fullPath = n.fullPath
return value
return
}
if len(n.children) == 1 {
// No handle found. Check if a handle for this path + a
@@ -549,18 +539,11 @@ walk: // Outer loop for walking the tree
n = n.children[0]
value.tsr = (n.path == "/" && n.handlers != nil) || (n.path == "" && n.indices == "/")
}
return value
return
case catchAll:
// Save param value
if params != nil {
// Preallocate capacity if necessary
if cap(*params) < int(globalParamsCount) {
newParams := make(Params, len(*params), globalParamsCount)
copy(newParams, *params)
*params = newParams
}
if value.params == nil {
value.params = params
}
@@ -581,7 +564,7 @@ walk: // Outer loop for walking the tree
value.handlers = n.handlers
value.fullPath = n.fullPath
return value
return
default:
panic("invalid node type")
@@ -612,7 +595,7 @@ walk: // Outer loop for walking the tree
// Check if this node has a handle registered.
if value.handlers = n.handlers; value.handlers != nil {
value.fullPath = n.fullPath
return value
return
}
// If there is no handle for this route, but this route has a
@@ -620,12 +603,12 @@ walk: // Outer loop for walking the tree
// additional trailing slash
if path == "/" && n.wildChild && n.nType != root {
value.tsr = true
return value
return
}
if path == "/" && n.nType == static {
value.tsr = true
return value
return
}
// No handle found. Check if a handle for this path + a
@@ -635,11 +618,11 @@ walk: // Outer loop for walking the tree
n = n.children[i]
value.tsr = (len(n.path) == 1 && n.handlers != nil) ||
(n.nType == catchAll && n.children[0].handlers != nil)
return value
return
}
}
return value
return
}
// Nothing found. We can recommend to redirect to the same URL with an
@@ -665,7 +648,7 @@ walk: // Outer loop for walking the tree
}
}
return value
return
}
}