A rewrite with a smaller API. See MIGRATION.md for the before and after of every call.
fastrouterpackage for fasthttp, sonet/httpusers no longer link fasthttp.- Functional options for
New:WithMiddleware,WithNotFound,WithMethodNotAllowed. Use(pattern, mw...)andUseMethod(method, pattern, mw...)for middleware scoped to the routes below a path.Routes()lists the registered routes.- Params on
net/httpare read with the standardr.PathValue, andr.Patternholds the matched pattern. fastrouter.Param(ctx, name)reads params on fasthttp.- Custom methods work everywhere, including the
Allowheader andMount, which takes every method. - Runnable examples in
examples/, each with a test.
- Module path is
github.com/vardius/gorouter/v5; Go 1.26 or newer is required. - Matching allocates nothing. Middleware chains are composed once at registration instead of on every request:
a route behind three middleware went from 170 ns and 6 allocations to 24 ns and none on
net/http. - On fasthttp, params are pooled and released with the request: routing allocates nothing. Param values are copies, valid until the handler returns even if it rewrites the path.
Usepicks routes by pattern rather than by request path, and panics for paths below a mount, where it could never run.- On fasthttp,
Mountdecodes the path once, not twice, and puts the caller's path and params back when the mounted handler returns. - The method helpers (
GET,POST, …) take a handler func; useHandlefor any otherhttp.Handler. - Regexp params match the whole segment and can't contain a slash.
- Invalid patterns and duplicate routes panic at registration with a message naming the problem.
- The
context,middleware,muxandpathpackages. RouterandFastHTTPRouterinterfaces, in favour of the concrete*gorouter.Routerand*fastrouter.Router.NewFastHTTPRouter,USE,USEANY,NotFound,NotAllowed,ServeFiles,CompileandPrettyPrint.
- Fixed a data race where concurrent requests could run each other's middleware.
Compileno longer drops routes or middleware on nodes it merges.- Middleware on
/ano longer applies to/abc. - Regexp params match the whole segment, and an expression may contain a colon.
- An unclosed
{namepanics at registration. - The root path
/answers 405 with anAllowheader when another method has a route there. Mountover a middleware-only path works, and panics when routes already live under the mount path.- Go 1.26 and the latest dependencies.