MCPcopy
hub / github.com/julienschmidt/httprouter / Handler

Method Handler

router.go:267–278  ·  view source on GitHub ↗

Handler is an adapter which allows the usage of an http.Handler as a request handle. The Params are available in the request context under ParamsKey.

(method, path string, handler http.Handler)

Source from the content-addressed store, hash-verified

265// request handle.
266// The Params are available in the request context under ParamsKey.
267func (r *Router) Handler(method, path string, handler http.Handler) {
268 r.Handle(method, path,
269 func(w http.ResponseWriter, req *http.Request, p Params) {
270 if len(p) > 0 {
271 ctx := req.Context()
272 ctx = context.WithValue(ctx, ParamsKey, p)
273 req = req.WithContext(ctx)
274 }
275 handler.ServeHTTP(w, req)
276 },
277 )
278}
279
280// HandlerFunc is an adapter which allows the usage of an http.HandlerFunc as a
281// request handle.

Callers 2

HandlerFuncMethod · 0.95
TestRouterAPIFunction · 0.80

Calls 2

HandleMethod · 0.95
ServeHTTPMethod · 0.45

Tested by 1

TestRouterAPIFunction · 0.64