Documentation
¶
Overview ¶
Package matcher provides route pattern matching with best-match semantics.
It is intended for routers that need exactly one resolved route per request path, including support for dynamic params and splats.
Index ¶
- func EnsureLeadingAndTrailingSlash(pattern string) string
- func EnsureLeadingSlash(pattern string) string
- func EnsureTrailingSlash(pattern string) string
- func HasLeadingSlash(pattern string) bool
- func HasTrailingSlash(pattern string) bool
- func JoinPatterns(rp *RegisteredPattern, pattern string) string
- func ParseSegments(path string) []string
- func StripLeadingSlash(pattern string) string
- func StripTrailingSlash(pattern string) string
- type BestMatch
- type Matcher
- func (m *Matcher) DynamicParamPrefix() rune
- func (m *Matcher) FindBestMatch(realPath string) (*BestMatch, bool)
- func (m *Matcher) NormalizePattern(originalPattern string) *RegisteredPattern
- func (m *Matcher) RegisterPattern(originalPattern string) *RegisteredPattern
- func (m *Matcher) SplatSegmentIdentifier() rune
- type Options
- type Params
- type RegisteredPattern
- type Segment
- type SegmentType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureLeadingAndTrailingSlash ¶
EnsureLeadingAndTrailingSlash ensures both leading and trailing slashes.
func EnsureLeadingSlash ¶
EnsureLeadingSlash ensures a leading slash exists.
func EnsureTrailingSlash ¶
EnsureTrailingSlash ensures a trailing slash exists.
func HasLeadingSlash ¶
HasLeadingSlash reports whether pattern starts with '/'.
func HasTrailingSlash ¶
HasTrailingSlash reports whether pattern ends with '/'.
func JoinPatterns ¶
func JoinPatterns(rp *RegisteredPattern, pattern string) string
JoinPatterns joins a registered pattern with a pattern suffix.
func ParseSegments ¶
ParseSegments splits a path into matcher segments.
func StripLeadingSlash ¶
StripLeadingSlash removes a leading slash when present.
func StripTrailingSlash ¶
StripTrailingSlash removes a trailing slash when present.
Types ¶
type BestMatch ¶
type BestMatch = matchercore.BestMatch
BestMatch is the highest-scoring single match for a path.
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher resolves route patterns for one option configuration.
func (*Matcher) DynamicParamPrefix ¶
DynamicParamPrefix returns the dynamic parameter prefix rune.
func (*Matcher) FindBestMatch ¶
FindBestMatch resolves the highest-scoring single match for realPath.
func (*Matcher) NormalizePattern ¶
func (m *Matcher) NormalizePattern(originalPattern string) *RegisteredPattern
NormalizePattern validates and normalizes one input pattern.
func (*Matcher) RegisterPattern ¶
func (m *Matcher) RegisterPattern(originalPattern string) *RegisteredPattern
RegisterPattern registers one pattern into matcher indices.
func (*Matcher) SplatSegmentIdentifier ¶
SplatSegmentIdentifier returns the splat segment identifier rune.
type Options ¶
type Options struct {
// Optional. Defaults to ':'.
DynamicParamPrefix rune
// Optional. Defaults to '*'.
SplatSegmentIdentifier rune
// Optional. Defaults to false.
Quiet bool
}
Options configures matcher behavior.
type Params ¶
type Params = matchercore.Params
Params stores dynamic path parameter values extracted from a match.
type RegisteredPattern ¶
type RegisteredPattern = matchercore.RegisteredPattern
RegisteredPattern is normalized metadata for one registered pattern.
type Segment ¶
type Segment = matchercore.Segment
Segment is a normalized pattern segment and its classification.
type SegmentType ¶
type SegmentType = matchercore.SegmentType
SegmentType identifies the kind of one route segment.