diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2026-10-02 15:02:43 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2026-10-02 15:02:43 +0200 |
| commit | 1635adc08aa413bbd7d2cf67e66ad6e9a823169a (patch) | |
| tree | e85a855893ce3632d3d43e58891208653fb70cb8 /pathrouter/handler.go | |
| parent | 7b1cca50c21a6156824e276e2b6c662d33cc9071 (diff) | |
| download | go-gg-1635adc08aa413bbd7d2cf67e66ad6e9a823169a.tar.gz | |
pathrouter: replace `vars` by new type Context
This is a breaking change, but there are no real users of this package
yet. I want to use the opportunity to have an extensible type here,
esp. to later add a cheaper alternative to context.Context.WithValue()
that is baked by just `map[reflect.Type]any` instead of a stack of
contexts.
Diffstat (limited to 'pathrouter/handler.go')
| -rw-r--r-- | pathrouter/handler.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/pathrouter/handler.go b/pathrouter/handler.go index ca493be..1ecabdd 100644 --- a/pathrouter/handler.go +++ b/pathrouter/handler.go @@ -16,7 +16,7 @@ import ( // // Package pathrouter passes variables explicitly like this, instead of via [context.Context.WithValue], // because doing so imposes a performance penalty for every usage of the respective context. -type HandlerFunc = func(w http.ResponseWriter, r *http.Request, vars map[string]string) +type HandlerFunc = func(w http.ResponseWriter, r *http.Request, rc Context) // ByMethod is a set of request handlers matching the same request path, keyed on request method. // It is commonly constructed as a literal using the respective constants from the net/http package, such as [http.MethodGet]. @@ -62,10 +62,10 @@ func Handlers(m ByMethod) Matcher { // precomputations for accept() allowHeader := m.buildAllowHeader() - serve := func(w http.ResponseWriter, r *http.Request, vars map[string]string) { + serve := func(w http.ResponseWriter, r *http.Request, rc Context) { handler, ok := m[r.Method] if ok { - handler(w, r, vars) + handler(w, r, rc) return } @@ -80,7 +80,7 @@ func Handlers(m ByMethod) Matcher { return realMatcher{ minLength: 0, maxLength: Some(0), - accept: func(path []string, vars map[string]string) HandlerFunc { + accept: func(path []string, rc Context) HandlerFunc { if len(path) != 0 { return nil } |
