Skip to content

Commit f184213

Browse files
Corné de JongAlexVulaj
Corné de Jong
authored andcommitted
Updated comments and some consistency fixes
1 parent 0e6f2da commit f184213

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

middleware.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func (r *Router) useInterface(mw middleware) {
3434

3535
// RouteMiddleware -------------------------------------------------------------
3636

37+
// 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 Route. Route middleware are executed after the Router middleware but before the Route handler.
3738
func (r *Route) Use(mwf ...MiddlewareFunc) *Route {
3839
for _, fn := range mwf {
3940
r.middlewares = append(r.middlewares, fn)
@@ -42,7 +43,7 @@ func (r *Route) Use(mwf ...MiddlewareFunc) *Route {
4243
return r
4344
}
4445

45-
// 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.
46+
// useInterface 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 Route. Route middleware are executed after the Router middleware but before the Route handler.
4647
func (r *Route) useInterface(mw middleware) {
4748
r.middlewares = append(r.middlewares, mw)
4849
}

route.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func (r *Route) Match(req *http.Request, match *RouteMatch) bool {
102102
match.Route = r
103103
}
104104
if match.Handler == nil {
105-
// for the matched handler, wrap it in the assigned middleware
106-
match.Handler = r.WrapHandlerInMiddleware(r.handler)
105+
// for the matched handler, wrap it in the assigned middlewares
106+
match.Handler = r.WrapHandlerInMiddlewares(r.handler)
107107
}
108108

109109
// Set variables.
@@ -146,10 +146,9 @@ func (r *Route) GetHandler() http.Handler {
146146
return r.handler
147147
}
148148

149-
// WrapHandlerInMiddleware wraps the supplied handler in the middleware
150-
// that were assigned to this route. If no middleware specified
151-
// the handler is returned
152-
func (r *Route) WrapHandlerInMiddleware(handler http.Handler) http.Handler {
149+
// WrapHandlerInMiddleware wraps the route handler in the assigned middlewares.
150+
// If no middlewares are specified, just the handler is returned.
151+
func (r *Route) WrapHandlerInMiddlewares(handler http.Handler) http.Handler {
153152
if len(r.middlewares) > 0 {
154153
for i := len(r.middlewares) - 1; i >= 0; i-- {
155154
handler = r.middlewares[i].Middleware(handler)

0 commit comments

Comments
 (0)