Skip to content

Commit

Permalink
Make Use() variadic (#355)
Browse files Browse the repository at this point in the history
Enables neater syntax when chaining several middleware functions.
  • Loading branch information
jsvensson authored and kisielk committed Mar 14, 2018
1 parent 07ba1fd commit 4dbd923
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ func (mw MiddlewareFunc) Middleware(handler http.Handler) http.Handler {
}

// 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.
func (r *Router) Use(mwf MiddlewareFunc) {
r.middlewares = append(r.middlewares, mwf)
func (r *Router) Use(mwf ...MiddlewareFunc) {
for _, fn := range mwf {
r.middlewares = append(r.middlewares, fn)
}
}

// 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.
Expand Down

0 comments on commit 4dbd923

Please sign in to comment.