middleware stacking bug fix
This commit is contained in:
13
resource.go
13
resource.go
@@ -34,19 +34,10 @@ func (m *Mux) Resource(pattern string, fn func(res *Resource), mw ...func(http.H
|
||||
panic("mux: Resource() requires callback")
|
||||
}
|
||||
|
||||
// Copy root middlewares.
|
||||
mws := make([]func(http.Handler) http.Handler, len(m.middlewares)+len(mw))
|
||||
copy(mws, m.middlewares)
|
||||
|
||||
// Append inline middlewares.
|
||||
if len(mw) > 0 {
|
||||
mws = append(mws, mw...)
|
||||
}
|
||||
|
||||
fn(&Resource{
|
||||
mux: m.mux,
|
||||
pattern: pattern,
|
||||
middlewares: mws,
|
||||
middlewares: copyMW(m.middlewares, mw),
|
||||
routes: m.routes,
|
||||
})
|
||||
}
|
||||
@@ -130,7 +121,7 @@ func (res *Resource) handlerFunc(method, pattern string, h http.HandlerFunc) {
|
||||
}
|
||||
|
||||
path := fmt.Sprintf("%s %s", method, pattern)
|
||||
res.mux.Handle(path, stack(res.middlewares, h))
|
||||
res.mux.Handle(path, stack(h, res.middlewares))
|
||||
}
|
||||
|
||||
// Use will register middleware(s) on Router stack.
|
||||
|
Reference in New Issue
Block a user