diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-05-01 22:16:06 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-05-01 22:16:06 -0600 |
commit | 3d5acb3b68af936d1820770d6094d96c65a9c0d3 (patch) | |
tree | ce997e3933cdba67069de4f3baf92162039eadc8 /router.go | |
parent | 0ba3a2779fdc3966070eae6bf05fbaa8d5bc6807 (diff) |
fix the router.Handler signature
Diffstat (limited to 'router.go')
-rw-r--r-- | router.go | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -39,18 +39,20 @@ func (r *Router) Route(pattern string, handler Handler) { r.routeAdded = true } -// Handler matches against the request path and dipatches to a route handler. +// Handler builds a Handler which matches the request path and dispatches to a route. // -// If no route matches, it returns a nil response. +// If no route matches, the handler returns a nil response. // Captured path parameters will be stored in the context passed into the handler // and can be retrieved with RouteParams(). -func (r Router) Handler(ctx context.Context, request *Request) *Response { - handler, params := r.Match(request) - if handler == nil { - return nil - } +func (r Router) Handler() Handler { + return HandlerFunc(func(ctx context.Context, request *Request) *Response { + handler, params := r.Match(request) + if handler == nil { + return nil + } - return handler.Handle(context.WithValue(ctx, routeParamsKey, params), request) + return handler.Handle(context.WithValue(ctx, routeParamsKey, params), request) + }) } // Match returns the matched handler and captured path parameters, or (nil, nil). |