nestedmatcher

package
v0.85.0-pre.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: BSD-3-Clause Imports: 1 Imported by: 0

README

kit/nestedmatcher

github.com/vormadev/vorma/kit/nestedmatcher

Nested route matcher for parent-to-leaf match stacks.

Use this package when one real path should resolve to multiple route patterns in order, such as layout/loader style routing.

Import

import "github.com/vormadev/vorma/kit/nestedmatcher"

Quick Start

m := nestedmatcher.New(nil)

m.RegisterPattern("")
m.RegisterPattern("/users")
m.RegisterPattern("/users/:id")

results, ok := m.FindMatches("/users/42")
if ok {
	_ = results.Matches      // ordered root -> leaf matches
	_ = results.Params["id"] // "42"
}

Options

Defaults:

  • DynamicParamPrefix: ':'
  • SplatSegmentIdentifier: '*'
  • ExplicitIndexSegmentIdentifier: "" (disabled)
  • Quiet: false (duplicate-registration warnings enabled)

Match Behavior

  • FindMatches returns every matched pattern in nested order.
  • Dynamic params and splats are accumulated once for the resolved path.
  • Returns (*Results, false) when no nested matches exist.

Lifecycle And Concurrency Notes

  • Register patterns before serving traffic.
  • Treat matcher registration as setup-time mutation, not request-time mutation.
  • NormalizePattern validates and returns normalized metadata without registering.

Public API

Types
  • type Matcher
  • type Options
  • type Params
  • type RegisteredPattern
  • type Segment
  • type SegmentType
  • type Match
  • type Results
Constructor
  • func New(opts *Options) *Matcher
Matcher methods
  • func (m *Matcher) ExplicitIndexSegmentIdentifier() string
  • func (m *Matcher) DynamicParamPrefix() rune
  • func (m *Matcher) SplatSegmentIdentifier() rune
  • func (m *Matcher) NormalizePattern(originalPattern string) *RegisteredPattern
  • func (m *Matcher) RegisterPattern(originalPattern string) *RegisteredPattern
  • func (m *Matcher) FindMatches(realPath string) (*Results, bool)

Documentation

Overview

Package nestedmatcher provides nested route matching semantics where one real path can resolve to multiple hierarchical route patterns.

It is intended for loader/layout-style routing where parent and leaf routes are accumulated together as one ordered match stack.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Match

type Match = matchercore.Match

Match represents one nested route match.

type Matcher

type Matcher struct {
	// contains filtered or unexported fields
}

Matcher resolves nested route matches.

func New

func New(opts *Options) *Matcher

New constructs a nested matcher with defaulted options.

func (*Matcher) DynamicParamPrefix

func (m *Matcher) DynamicParamPrefix() rune

DynamicParamPrefix returns the dynamic parameter prefix rune.

func (*Matcher) ExplicitIndexSegmentIdentifier

func (m *Matcher) ExplicitIndexSegmentIdentifier() string

ExplicitIndexSegmentIdentifier returns the explicit index marker.

func (*Matcher) FindMatches

func (m *Matcher) FindMatches(realPath string) (*Results, bool)

FindMatches resolves all nested matches for a real path.

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 for nested matching.

func (*Matcher) SplatSegmentIdentifier

func (m *Matcher) SplatSegmentIdentifier() rune

SplatSegmentIdentifier returns the splat segment identifier rune.

type Options

type Options = matchercore.Options

Options configures nested 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 Results

Results stores nested match resolution output.

type Segment

type Segment = matchercore.Segment

Segment is a normalized pattern segment and its classification.

type SegmentType

type SegmentType = matchercore.SegmentType

SegmentType identifies what kind of route segment is represented.

Jump to

Keyboard shortcuts

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