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/matcher.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/matcher.go')
| -rw-r--r-- | pathrouter/matcher.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/pathrouter/matcher.go b/pathrouter/matcher.go index f0f98ec..45ba818 100644 --- a/pathrouter/matcher.go +++ b/pathrouter/matcher.go @@ -51,8 +51,8 @@ // so any slashes that were encoded as %2F in the URL path will be considered part of a path element instead of a boundary. // // For instance, using the example above, the URL path "/v1/objects/42/23" would not match and generate a 404 response, -// but the URL path "/v1/objects/42%2F23" would match and invoke (e.g. with method GET) the GetObject handler with vars["id"] = "42/23". -// Like in this example, [HandlerFunc] will receive unescaped values in its vars argument. +// but the URL path "/v1/objects/42%2F23" would match and invoke (e.g. with method GET) the GetObject handler with rc.Variable("id") = "42/23". +// Like in this example, [HandlerFunc] will receive a [Context] in which [Context.Variable] calls returns unescaped values. // // # Implicit normalizations // @@ -97,7 +97,7 @@ type Matcher interface { } type realMatcher struct { - accept func(path []string, vars map[string]string) HandlerFunc + accept func(path []string, rc Context) HandlerFunc // The smallest len(path) that accept() can accept. minLength int @@ -115,12 +115,12 @@ func (m realMatcher) ServeHTTP(w http.ResponseWriter, r *http.Request) { // TryServeHTTP implements the [Matcher] interface. func (m realMatcher) TryServeHTTP(w http.ResponseWriter, r *http.Request) bool { path := extractPath(r.URL) - vars := make(map[string]string) - handlerFunc := m.accept(path, vars) + rc := newContext() + handlerFunc := m.accept(path, rc) if handlerFunc == nil { return false } else { - handlerFunc(w, r, vars) + handlerFunc(w, r, rc) return true } } |
