summaryrefslogtreecommitdiff
path: root/pathrouter/matcher.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-10-05 22:21:26 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-10-05 22:21:26 +0200
commit43a403b45d9644e634c2c560d16331305d83a4b0 (patch)
tree8ec3825579b388c205edfebed76b04906ae5368f /pathrouter/matcher.go
parent6e5880aca9744d5e21434708f550f383400966e4 (diff)
downloadgo-gg-43a403b45d9644e634c2c560d16331305d83a4b0.tar.gz
pathrouter: remove type Context from public interface
Diffstat (limited to 'pathrouter/matcher.go')
-rw-r--r--pathrouter/matcher.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/pathrouter/matcher.go b/pathrouter/matcher.go
index 45ba818..0ddd7f6 100644
--- a/pathrouter/matcher.go
+++ b/pathrouter/matcher.go
@@ -49,10 +49,10 @@
//
// Path matching is performed on the escaped form of the URL path, as returned by [url.URL.EscapedPath],
// so any slashes that were encoded as %2F in the URL path will be considered part of a path element instead of a boundary.
+// After matching, [VariableValue] calls return unescaped values.
//
// 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 rc.Variable("id") = "42/23".
-// Like in this example, [HandlerFunc] will receive a [Context] in which [Context.Variable] calls returns unescaped values.
+// but the URL path "/v1/objects/42%2F23" would match and invoke (e.g. with method GET) the GetObject handler with pathrouter.VariableValue(r, "id") = "42/23".
//
// # Implicit normalizations
//
@@ -97,7 +97,7 @@ type Matcher interface {
}
type realMatcher struct {
- accept func(path []string, rc Context) HandlerFunc
+ accept func(path []string, rc routingContext) http.HandlerFunc
// The smallest len(path) that accept() can accept.
minLength int
@@ -115,12 +115,13 @@ 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)
- rc := newContext()
+ var rc routingContext
+ r, rc = injectContext(r)
handlerFunc := m.accept(path, rc)
if handlerFunc == nil {
return false
} else {
- handlerFunc(w, r, rc)
+ handlerFunc(w, r)
return true
}
}