Skip to content

Commit 525206d

Browse files
Corné de JongAlexVulaj
Corné de Jong
authored andcommitted
wrapper to getter
1 parent f184213 commit 525206d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Diff for: route.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ 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 middlewares
106-
match.Handler = r.WrapHandlerInMiddlewares(r.handler)
105+
match.Handler = r.GetHandlerWithMiddlewares()
107106
}
108107

109108
// Set variables.
@@ -146,10 +145,12 @@ func (r *Route) GetHandler() http.Handler {
146145
return r.handler
147146
}
148147

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 {
152-
if len(r.middlewares) > 0 {
148+
// GetHandlerWithMiddleware returns the route handler wrapped in the assigned middlewares.
149+
// If no middlewares are specified, just the handler, if any, is returned.
150+
func (r *Route) GetHandlerWithMiddlewares() http.Handler {
151+
handler := r.handler
152+
153+
if handler != nil && len(r.middlewares) > 0 {
153154
for i := len(r.middlewares) - 1; i >= 0; i-- {
154155
handler = r.middlewares[i].Middleware(handler)
155156
}

0 commit comments

Comments
 (0)