@@ -37,6 +37,8 @@ import (
37
37
// |
38
38
// +---- emails
39
39
type Tree [T any ] struct {
40
+ name string // 名称
41
+
40
42
methods map [string ]int // 保存着每个请求方法在所有子节点上的数量。
41
43
node * node [T ] // 空节点,正好用于处理 OPTIONS *。
42
44
@@ -50,13 +52,22 @@ type Tree[T any] struct {
50
52
methodNotAllowedBuilder types.BuildNodeHandleOf [T ]
51
53
}
52
54
53
- func New [T any ](lock bool , i * syntax.Interceptors , notFound T , trace bool , methodNotAllowedBuilder , optionsBuilder types.BuildNodeHandleOf [T ]) * Tree [T ] {
55
+ func New [T any ](
56
+ name string ,
57
+ lock bool ,
58
+ i * syntax.Interceptors ,
59
+ notFound T ,
60
+ trace bool ,
61
+ methodNotAllowedBuilder ,
62
+ optionsBuilder types.BuildNodeHandleOf [T ],
63
+ ) * Tree [T ] {
54
64
s , err := i .NewSegment ("" )
55
65
if err != nil {
56
66
panic ("发生了不该发生的错误,应该是 syntax.NewSegment 逻辑发生变化" + err .Error ())
57
67
}
58
68
59
69
t := & Tree [T ]{
70
+ name : name ,
60
71
methods : make (map [string ]int , len (Methods )),
61
72
node : & node [T ]{segment : s , methodIndex : methodIndexMap [http .MethodOptions ]},
62
73
@@ -79,6 +90,8 @@ func New[T any](lock bool, i *syntax.Interceptors, notFound T, trace bool, metho
79
90
return t
80
91
}
81
92
93
+ func (tree * Tree [T ]) Name () string { return tree .name }
94
+
82
95
// Add 添加路由项
83
96
//
84
97
// methods 可以为空,表示添所有支持的请求方法,其中的 HEAD 和 OPTIONS 不受控。
@@ -291,6 +304,6 @@ func (tree *Tree[T]) URL(buf *errwrap.StringBuilder, pattern string, ps map[stri
291
304
292
305
// ApplyMiddleware 为已有的路由项添加中间件
293
306
func (tree * Tree [T ]) ApplyMiddleware (ms ... types.MiddlewareOf [T ]) {
294
- tree .notFound = ApplyMiddleware (tree .notFound , "" , "" , ms ... )
307
+ tree .notFound = ApplyMiddleware (tree .notFound , "" , "" , tree . Name (), ms ... )
295
308
tree .node .applyMiddleware (ms ... )
296
309
}
0 commit comments