Help us shape the future of Go! Take the 2026 Go Developer Survey

pathpattern

package
v0.151.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 6 Imported by: 3

Documentation

Overview

Package pathpattern implements path matching.

Examples of supported patterns:

  • "/"
  • "/abc""
  • "/abc/{variable}" (matches until next '/' or end-of-string)
  • "/abc/{variable*}" (matches everything, including "/abc" if "/abc" has root)
  • "/abc/{ variable | prefix_(.*}_suffix }" (matches regular expressions)

Index

Constants

View Source
const (
	// SuffixKindConstant matches a constant string
	SuffixKindConstant = SuffixKind(iota)

	// SuffixKindRegExp matches a regular expression
	SuffixKindRegExp

	// SuffixKindVariable matches everything until '/'
	SuffixKindVariable

	// SuffixKindEverything matches everything (until end-of-string)
	SuffixKindEverything
)

Note that order is important!

Variables

View Source
var DefaultOptions = &Options{
	SupportWildcard: true,
}

Functions

func EqualSuffix

func EqualSuffix(a, b Suffix) bool

func PathFromHost

func PathFromHost(host string, specialDashes bool) string

PathFromHost converts a host pattern to a path pattern.

Examples:

  • PathFromHost("some-subdomain.domain.com", false) -> "com/./domain/./some-subdomain"
  • PathFromHost("some-subdomain.domain.com", true) -> "com/./domain/./subdomain/-/some"

Types

type Node

type Node struct {
	VariableNames []string
	Value         any
	Suffixes      SuffixList
}

func (*Node) Add

func (currentNode *Node) Add(path string, value any, options *Options) error

func (*Node) CreateNode

func (currentNode *Node) CreateNode(path string, options *Options) (*Node, error)

func (*Node) Match

func (currentNode *Node) Match(path string) (*Node, []string)

func (*Node) MustAdd

func (currentNode *Node) MustAdd(path string, value any, options *Options)

func (*Node) String

func (currentNode *Node) String() string

type Options

type Options struct {
	SupportWildcard bool
	SupportRegExp   bool
}

type Suffix

type Suffix struct {
	Kind    SuffixKind
	Pattern string

	// Next node
	Node *Node
	// contains filtered or unexported fields
}

Suffix describes condition that

func (Suffix) String

func (suffix Suffix) String() string

type SuffixKind

type SuffixKind int

type SuffixList

type SuffixList []Suffix

Jump to

Keyboard shortcuts

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