MCPcopy
hub / github.com/go-chi/chi / With

Method With

mux.go:236–257  ·  view source on GitHub ↗

With adds inline middlewares for an endpoint handler.

(middlewares ...func(http.Handler) http.Handler)

Source from the content-addressed store, hash-verified

234
235// With adds inline middlewares for an endpoint handler.
236func (mx *Mux) With(middlewares ...func(http.Handler) http.Handler) Router {
237 // Similarly as in handle(), we must build the mux handler once additional
238 // middleware registration isn't allowed for this stack, like now.
239 if !mx.inline && mx.handler == nil {
240 mx.updateRouteHandler()
241 }
242
243 // Copy middlewares from parent inline muxs
244 var mws Middlewares
245 if mx.inline {
246 mws = make(Middlewares, len(mx.middlewares))
247 copy(mws, mx.middlewares)
248 }
249 mws = append(mws, middlewares...)
250
251 im := &Mux{
252 pool: mx.pool, inline: true, parent: mx, tree: mx.tree, middlewares: mws,
253 notFoundHandler: mx.notFoundHandler, methodNotAllowedHandler: mx.methodNotAllowedHandler,
254 }
255
256 return im
257}
258
259// Group creates a new inline-Mux with a copy of middleware stack. It's useful
260// for a group of handlers along the same routing path that use an additional

Callers 2

GroupMethod · 0.95

Calls 1

updateRouteHandlerMethod · 0.95

Tested by 1