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)
| 265 | // request handle. |
| 266 | // The Params are available in the request context under ParamsKey. |
| 267 | func (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. |