Skip to content

Commit 4dbd923

Browse files
jsvenssonkisielk
authored andcommitted
Make Use() variadic (#355)
Enables neater syntax when chaining several middleware functions.
1 parent 07ba1fd commit 4dbd923

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

middleware.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ func (mw MiddlewareFunc) Middleware(handler http.Handler) http.Handler {
1818
}
1919

2020
// Use appends a MiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify requests and/or responses, and are executed in the order that they are applied to the Router.
21-
func (r *Router) Use(mwf MiddlewareFunc) {
22-
r.middlewares = append(r.middlewares, mwf)
21+
func (r *Router) Use(mwf ...MiddlewareFunc) {
22+
for _, fn := range mwf {
23+
r.middlewares = append(r.middlewares, fn)
24+
}
2325
}
2426

2527
// useInterface appends a middleware to the chain. Middleware can be used to intercept or otherwise modify requests and/or responses, and are executed in the order that they are applied to the Router.

0 commit comments

Comments
 (0)