@@ -6,6 +6,7 @@ package mux
6
6
7
7
import (
8
8
"net/http"
9
+ "slices"
9
10
"strconv"
10
11
11
12
"github.com/issue9/errwrap"
@@ -271,6 +272,7 @@ func (p *PrefixOf[T]) URL(strict bool, pattern string, params map[string]string)
271
272
//
272
273
// m 中间件函数,按顺序调用,会继承 p 的中间件并按在 m 之前;
273
274
func (p * PrefixOf [T ]) Prefix (prefix string , m ... types.MiddlewareOf [T ]) * PrefixOf [T ] {
275
+ // TODO(go1.22): slices.Concat(p.middleware, m)
274
276
ms := make ([]types.MiddlewareOf [T ], 0 , len (p .middleware )+ len (m ))
275
277
ms = append (ms , p .middleware ... )
276
278
ms = append (ms , m ... )
@@ -282,9 +284,7 @@ func (p *PrefixOf[T]) Prefix(prefix string, m ...types.MiddlewareOf[T]) *PrefixO
282
284
// prefix 路由前缀字符串,可以为空;
283
285
// m 中间件函数,按顺序调用,会继承 r 的中间件并按在 m 之前;
284
286
func (r * RouterOf [T ]) Prefix (prefix string , m ... types.MiddlewareOf [T ]) * PrefixOf [T ] {
285
- ms := make ([]types.MiddlewareOf [T ], 0 , len (m ))
286
- ms = append (ms , m ... )
287
- return & PrefixOf [T ]{router : r , prefix : prefix , middleware : ms }
287
+ return & PrefixOf [T ]{router : r , prefix : prefix , middleware : slices .Clone (m )}
288
288
}
289
289
290
290
// Router 返回与当前关联的 *RouterOf 实例
@@ -332,16 +332,15 @@ func (r *ResourceOf[T]) URL(strict bool, params map[string]string) (string, erro
332
332
// pattern 资源地址;
333
333
// m 中间件函数,按顺序调用,会继承 r 的中间件并按在 m 之前;
334
334
func (r * RouterOf [T ]) Resource (pattern string , m ... types.MiddlewareOf [T ]) * ResourceOf [T ] {
335
- ms := make ([]types.MiddlewareOf [T ], 0 , len (m ))
336
- ms = append (ms , m ... )
337
- return & ResourceOf [T ]{router : r , pattern : pattern , middleware : ms }
335
+ return & ResourceOf [T ]{router : r , pattern : pattern , middleware : slices .Clone (m )}
338
336
}
339
337
340
338
// Resource 创建一个资源路由项
341
339
//
342
340
// pattern 资源地址;
343
341
// m 中间件函数,按顺序调用,会继承 p 的中间件并按在 m 之前;
344
342
func (p * PrefixOf [T ]) Resource (pattern string , m ... types.MiddlewareOf [T ]) * ResourceOf [T ] {
343
+ // TODO(go1.22): slices.Concat(p.middleware, m)
345
344
ms := make ([]types.MiddlewareOf [T ], 0 , len (p .middleware )+ len (m ))
346
345
ms = append (ms , p .middleware ... )
347
346
ms = append (ms , m ... )
0 commit comments