aboutsummaryrefslogtreecommitdiff
path: root/pathrouter/catchallvariable.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-10-02 15:02:43 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-10-02 15:02:43 +0200
commit1635adc08aa413bbd7d2cf67e66ad6e9a823169a (patch)
treee85a855893ce3632d3d43e58891208653fb70cb8 /pathrouter/catchallvariable.go
parent7b1cca50c21a6156824e276e2b6c662d33cc9071 (diff)
downloadgo-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/catchallvariable.go')
-rw-r--r--pathrouter/catchallvariable.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/pathrouter/catchallvariable.go b/pathrouter/catchallvariable.go
index 1b98672..d1d3e2c 100644
--- a/pathrouter/catchallvariable.go
+++ b/pathrouter/catchallvariable.go
@@ -10,9 +10,10 @@ import (
)
// CatchAllVariable is a [Matcher] that accepts subpaths with an arbitrary number of path elements.
-// The value of any amount of leading path elements will be collected into vars[name],
+// The value of any amount of leading path elements will be collected into the [Context],
// such that the remainder is accepted by the next matcher.
-// At least one element must be collected into vars[name].
+// At least one element must be collected.
+// The full sequence of collected path elements can be retrieved with [Context.Variable].
//
// CatchAllVariable() may appear at any point within the routing tree,
// but it may not contain another CatchAllVariable() anywhere within it.
@@ -32,7 +33,7 @@ func catchAllVariable(name string, matcher realMatcher) Matcher {
panic("matcher within CatchAllVariable() may not accept unlimited path lengths")
}
- accept := func(path []string, vars map[string]string) HandlerFunc {
+ accept := func(path []string, rc Context) HandlerFunc {
for length := innerMinLength; length <= innerMaxLength; length++ {
if length > len(path) {
break
@@ -42,11 +43,11 @@ func catchAllVariable(name string, matcher realMatcher) Matcher {
continue
}
- handlerFunc := matcher.accept(subpath, vars)
+ handlerFunc := matcher.accept(subpath, rc)
if handlerFunc == nil {
continue
}
- vars[name] = pathUnescape(strings.Join(caughtPath, "/"))
+ rc.vars[name] = pathUnescape(strings.Join(caughtPath, "/"))
return handlerFunc
}
return nil