diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-02-15 16:44:29 -0700 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-02-15 16:44:29 -0700 |
commit | 46ad450327111b9d28b592658d75ef57da498298 (patch) | |
tree | 2b837bac9ae36d5a34dda06ba745850da216257d /README.md | |
parent | bc96af40db6104580c22086c8db7c8119a404257 (diff) |
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.
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -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. |