Documentation
¶
Overview ¶
Package matcher provides route pattern matching with support for static, dynamic, and splat segments. It supports two resolution modes:
- FindBestMatch: resolves the single highest-scoring route (for traditional routing).
- FindNestedMatches: resolves all hierarchical ancestor matches (for loader/layout routing).
Index ¶
- func EnsureLeadingAndTrailingSlash(p string) string
- func EnsureLeadingSlash(p string) string
- func EnsureTrailingSlash(p string) string
- func HasLeadingSlash(p string) bool
- func HasTrailingSlash(p string) bool
- func JoinPatterns(rp *RegisteredPattern, pattern string) string
- func ParseSegments(path string) []string
- func StripLeadingSlash(p string) string
- func StripTrailingSlash(p string) string
- type BestMatch
- type FindNestedMatchesResults
- type Matcher
- func (m *Matcher) DynamicParamPrefix() rune
- func (m *Matcher) ExplicitIndexSegmentIdentifier() string
- func (m *Matcher) FindBestMatch(real_path string) (*BestMatch, bool)
- func (m *Matcher) FindNestedMatches(real_path string) (*FindNestedMatchesResults, bool)
- func (m *Matcher) NormalizePattern(original string) *RegisteredPattern
- func (m *Matcher) RegisterPattern(original string) *RegisteredPattern
- func (m *Matcher) SplatSegmentIdentifier() rune
- type NestedMatch
- type Options
- type Params
- type RegisteredPattern
- type Segment
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureLeadingAndTrailingSlash ¶
EnsureLeadingAndTrailingSlash ensures both leading and trailing slashes.
func EnsureLeadingSlash ¶
func EnsureTrailingSlash ¶
func HasLeadingSlash ¶
func HasTrailingSlash ¶
func JoinPatterns ¶
func JoinPatterns(rp *RegisteredPattern, pattern string) string
JoinPatterns joins a registered pattern base with a suffix pattern.
func ParseSegments ¶
ParseSegments splits a URL path into route segments.
func StripLeadingSlash ¶
func StripTrailingSlash ¶
Types ¶
type BestMatch ¶
type BestMatch struct {
*RegisteredPattern
Params Params
SplatValues []string
// contains filtered or unexported fields
}
BestMatch is the highest-scoring single match for a real path.
type FindNestedMatchesResults ¶
type FindNestedMatchesResults struct {
Params Params
SplatValues []string
Matches []*NestedMatch
}
FindNestedMatchesResults stores all resolved nested matches.
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher stores registered patterns and resolves paths against them.
func (*Matcher) DynamicParamPrefix ¶
DynamicParamPrefix returns the configured dynamic parameter prefix rune.
func (*Matcher) ExplicitIndexSegmentIdentifier ¶
ExplicitIndexSegmentIdentifier returns the configured explicit index marker.
func (*Matcher) FindBestMatch ¶
FindBestMatch resolves the single highest-scoring match for a real path.
func (*Matcher) FindNestedMatches ¶
func (m *Matcher) FindNestedMatches( real_path string, ) (*FindNestedMatchesResults, bool)
FindNestedMatches resolves all hierarchical ancestor matches for a real path.
func (*Matcher) NormalizePattern ¶
func (m *Matcher) NormalizePattern(original string) *RegisteredPattern
NormalizePattern validates and normalizes one input pattern.
func (*Matcher) RegisterPattern ¶
func (m *Matcher) RegisterPattern(original string) *RegisteredPattern
RegisterPattern registers one pattern into the matcher. Panics on normalized-pattern collision from different original strings. Returns the existing entry when the same original is registered twice.
func (*Matcher) SplatSegmentIdentifier ¶
SplatSegmentIdentifier returns the configured splat segment identifier rune.
type NestedMatch ¶
type NestedMatch struct {
*RegisteredPattern
// contains filtered or unexported fields
}
NestedMatch represents one entry in a nested match result set.
func (*NestedMatch) Params ¶
func (m *NestedMatch) Params() Params
Params returns a defensive copy of dynamic params for this match.
func (*NestedMatch) SplatValues ¶
func (m *NestedMatch) SplatValues() []string
SplatValues returns a defensive copy of splat values for this match.
type Options ¶
type Options struct {
DynamicParamPrefix rune // Defaults to ':'.
SplatSegmentIdentifier rune // Defaults to '*'.
ExplicitIndexSegmentIdentifier string // Defaults to "" (trailing slash = index).
Quiet bool // Suppress duplicate-registration warnings.
}
Options configures matching semantics.
type RegisteredPattern ¶
type RegisteredPattern struct {
// contains filtered or unexported fields
}
RegisteredPattern is the normalized metadata for one registered pattern.
func (*RegisteredPattern) NormalizedPattern ¶
func (rp *RegisteredPattern) NormalizedPattern() string
NormalizedPattern returns the normalized pattern string.
func (*RegisteredPattern) NormalizedSegments ¶
func (rp *RegisteredPattern) NormalizedSegments() []Segment
NormalizedSegments returns a copy of the normalized segment list.
func (*RegisteredPattern) OriginalPattern ¶
func (rp *RegisteredPattern) OriginalPattern() string
OriginalPattern returns the pattern as originally registered.