Merge dc281f790c88eebdba270e7705f087d50d1a570f into c3d1092b3b48addf6f9cd00fe274ec3bd14650eb

This commit is contained in:
A1lo 2025-10-12 22:40:26 +08:00 committed by GitHub
commit 0b5440b834
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

19
gin.go
View File

@ -12,6 +12,7 @@ import (
"os" "os"
"path" "path"
"regexp" "regexp"
"slices"
"strings" "strings"
"sync" "sync"
@ -68,10 +69,11 @@ func (c HandlersChain) Last() HandlerFunc {
// RouteInfo represents a request route's specification which contains method and path and its handler. // RouteInfo represents a request route's specification which contains method and path and its handler.
type RouteInfo struct { type RouteInfo struct {
Method string Method string
Path string Path string
Handler string Handler string
HandlerFunc HandlerFunc HandlerFunc HandlerFunc
HandlersChain HandlersChain
} }
// RoutesInfo defines a RouteInfo slice. // RoutesInfo defines a RouteInfo slice.
@ -389,10 +391,11 @@ func iterate(path, method string, routes RoutesInfo, root *node) RoutesInfo {
if len(root.handlers) > 0 { if len(root.handlers) > 0 {
handlerFunc := root.handlers.Last() handlerFunc := root.handlers.Last()
routes = append(routes, RouteInfo{ routes = append(routes, RouteInfo{
Method: method, Method: method,
Path: path, Path: path,
Handler: nameOfFunction(handlerFunc), Handler: nameOfFunction(handlerFunc),
HandlerFunc: handlerFunc, HandlerFunc: handlerFunc,
HandlersChain: slices.Clone(root.handlers),
}) })
} }
for _, child := range root.children { for _, child := range root.children {