matcher

package
v0.85.0-pre.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureLeadingAndTrailingSlash

func EnsureLeadingAndTrailingSlash(p string) string

EnsureLeadingAndTrailingSlash ensures both leading and trailing slashes.

func EnsureLeadingSlash

func EnsureLeadingSlash(p string) string

func EnsureTrailingSlash

func EnsureTrailingSlash(p string) string

func HasLeadingSlash

func HasLeadingSlash(p string) bool

func HasTrailingSlash

func HasTrailingSlash(p string) bool

func JoinPatterns

func JoinPatterns(rp *RegisteredPattern, pattern string) string

JoinPatterns joins a registered pattern base with a suffix pattern.

func ParseSegments

func ParseSegments(path string) []string

ParseSegments splits a URL path into route segments.

func StripLeadingSlash

func StripLeadingSlash(p string) string

func StripTrailingSlash

func StripTrailingSlash(p string) string

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 New

func New(opts *Options) *Matcher

New constructs a Matcher with defaulted options.

func (*Matcher) DynamicParamPrefix

func (m *Matcher) DynamicParamPrefix() rune

DynamicParamPrefix returns the configured dynamic parameter prefix rune.

func (*Matcher) ExplicitIndexSegmentIdentifier

func (m *Matcher) ExplicitIndexSegmentIdentifier() string

ExplicitIndexSegmentIdentifier returns the configured explicit index marker.

func (*Matcher) FindBestMatch

func (m *Matcher) FindBestMatch(real_path string) (*BestMatch, bool)

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

func (m *Matcher) SplatSegmentIdentifier() rune

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 Params

type Params = map[string]string

Params stores dynamic path parameter values extracted from a match.

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.

type Segment

type Segment struct {
	NormalizedVal string
	Type          string // "static", "dynamic", "splat", "index"
}

Segment is a normalized route segment and its classification.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL