summaryrefslogtreecommitdiff
path: root/router.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-09-30 20:08:33 -0600
committertjpcc <tjp@ctrl-c.club>2023-09-30 20:08:53 -0600
commit775c0c1040e6a6622fec39d49b354bfa194a6998 (patch)
treef46edde7ee0392ae714f4facfd4e64244814c040 /router.go
parent09c482d5016cfc7b628058893a1644fdf5fa699f (diff)
file serving refactor
* do away with fs.FS usage in gemini, like the previous refactor in gopher * remove spartan code in contrib * standardize fsroot/urlroot string arguments to file serving handlers
Diffstat (limited to 'router.go')
-rw-r--r--router.go25
1 files changed, 15 insertions, 10 deletions
diff --git a/router.go b/router.go
index 65f8568..d45a7de 100644
--- a/router.go
+++ b/router.go
@@ -39,20 +39,25 @@ func (r *Router) Route(pattern string, handler Handler) {
r.routeAdded = true
}
-// Handler builds a Handler which matches the request path and dispatches to a route.
+// Handle implements Handler
//
-// If no route matches, the handler returns a nil response.
+// If no route matches, Handle returns a nil response.
// Captured path parameters will be stored in the context passed into the handler
// and can be retrieved with RouteParams().
-func (r Router) Handler() Handler {
- return HandlerFunc(func(ctx context.Context, request *Request) *Response {
- handler, params := r.Match(request)
- if handler == nil {
- return nil
- }
+func (r Router) Handle(ctx context.Context, request *Request) *Response {
+ handler, params := r.Match(request)
+ if handler == nil {
+ return nil
+ }
- return handler.Handle(context.WithValue(ctx, routeParamsKey, params), request)
- })
+ return handler.Handle(context.WithValue(ctx, routeParamsKey, params), request)
+}
+
+// Handler builds a Handler
+//
+// It is only here for compatibility because Router implements Handler directly.
+func (r Router) Handler() Handler {
+ return r
}
// Match returns the matched handler and captured path parameters, or (nil, nil).