mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-14 12:12:12 +08:00
feat(route): add handlers chain in RouteInfo
This commit is contained in:
parent
5dd833f1f2
commit
dc281f790c
19
gin.go
19
gin.go
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user