From 46ad450327111b9d28b592658d75ef57da498298 Mon Sep 17 00:00:00 2001 From: tjpcc Date: Wed, 15 Feb 2023 16:44:29 -0700 Subject: Switch Handler to an interface. HandlerFunc is much better as a function returning a Handler, rather than a newtype for the function type itself. This way there is no confusion creating a type-inferenced variable with HandlerFunc(func(... and then using a HandlerFunc where a Handler is expected. Much better to only have one public type. --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index ec1f735..592f652 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Gus is carefully structured as composable building blocks. The top-level package * a "Server" interface type * a "Handler" abstraction * a "Middleware" abstraction -* some useful Handler wrappers: filtering, falling through a list of handlers +* some useful Handler wrappers: a router, request filtering, falling through a list of handlers ## Protocols @@ -42,6 +42,16 @@ The gus/logging package provides everything you need to get a good basic start t * A request-logging middleware with common diagnostics (time, duration, url, status codes, response body lengths) * A simple constructor of useful default loggers at various levels. They output colorful logfmt lines to stdout. +## Routing + +The router in the gus package supports slash-delimited path pattern strings. In the segments of these patterns: + +* A "/:wildcard/" segment matches anything in that position, and captures the value as a route parameter. Or if the paramter name is omitted like "/:/", it matches anything in a single segment without capturing a paramter. +* A "/*remainder" segment is only allowed at the end and matches the rest of the path, capturing it into the paramter name. Or again, omitting a parameter name like "/*" simple matches any path suffix. +* Any other segment in the pattern must match the corresponding segment of a request exactly. + +Router also supports maintaining a list of middlewares at the router level, mounting sub-routers under a pattern, looking up the matching handler for any request, and of course acting as a Handler itself. + ## gus/contrib/* This is where useful building blocks themselves start to come in. Sub-packages of contrib include Handler and Middleware implementations which accomplish the things your servers actually need to do. -- cgit v1.2.3