summaryrefslogtreecommitdiff
path: root/pathrouter/context.go
diff options
context:
space:
mode:
Diffstat (limited to 'pathrouter/context.go')
-rw-r--r--pathrouter/context.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/pathrouter/context.go b/pathrouter/context.go
new file mode 100644
index 0000000..d47e302
--- /dev/null
+++ b/pathrouter/context.go
@@ -0,0 +1,23 @@
+// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
+// SPDX-License-Identifier: Apache-2.0
+
+package pathrouter
+
+// Context contains information about an HTTP request that has been processed by matchers from this package.
+// It appears as an argument in [HandlerFunc].
+type Context struct {
+ vars map[string]string
+}
+
+func newContext() Context {
+ return Context{
+ vars: make(map[string]string),
+ }
+}
+
+// Variable returns the path element(s) collected by a [Variable] or [CatchAllVariable] matcher with the given name,
+// with any URL escaping removed.
+// If no matcher with this name appeared in the path leading up to the handler, the empty string is returned.
+func (rc Context) Variable(name string) string {
+ return rc.vars[name]
+}