Documentation
¶
Overview ¶
Package router matches request paths against an ordered table of starlette-style path templates. The first route declared that matches wins: declaration order is the entire priority rule.
Index ¶
Constants ¶
const MaxRoutes = 1 << 16
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder[T any] struct { // contains filtered or unexported fields }
Builder accumulates a route table. A route's index is its position in the order added.
func NewBuilder ¶
type Mask ¶
type Mask uint32
Mask is an opaque per-route tag. A route fully matches when its mask intersects the query mask, and partially matches when only its template does.
type Router ¶
type Router[T any] struct { // contains filtered or unexported fields }
Router matches paths against a route table. It is built once and never mutated, so readers need no lock and a new table is published by a single atomic.Pointer store, which synchronises everything a reader reaches.
func (*Router[T]) Ambiguous ¶
Ambiguous returns the templates whose shape forces the matcher to backtrack - a param that a following literal can extend, adjacent params, or a non-final path convertor. The result is read-only.
func (*Router[T]) MarshalLogObject ¶
func (r *Router[T]) MarshalLogObject(e zapcore.ObjectEncoder) error
MarshalLogObject describes the table's shape. A Router holds no per-match state.
func (*Router[T]) Match ¶
Match returns the value of the first route in declaration order whose template matches path and whose mask intersects q. It returns ResultPartial when a template matched but no such route carried the mask, and ResultOverBudget when the search exceeded its step budget.
Match allocates nothing.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is a parsed starlette-style path template. Parsing mirrors starlette's compile_path exactly.
func ParseTemplate ¶
ParseTemplate parses a starlette path template. Custom convertors are rejected: only the five built-ins may travel over the wire.
func (*Template) Ambiguous ¶
Ambiguous reports whether the template's own shape can force the matcher to backtrack - a param a following literal can extend, adjacent params, or a non-final path convertor - independent of what other templates put in the tree.
func (*Template) Canonical ¶
Canonical returns a key identifying what the template matches: two templates with the same canonical form accept exactly the same paths and differ only in param names. Literals are length-prefixed so that a literal brace cannot forge a convertor - "/x/{:str}" is literal text, and must not collide with "/x/{a}".