package pathpattern

import "github.com/getkin/kin-openapi/routers/legacy/pathpattern"

Package pathpattern implements path matching.

Examples of supported patterns:

Index

Constants

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

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:

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

func (SuffixList) Len

func (list SuffixList) Len() int

func (SuffixList) Less

func (list SuffixList) Less(i, j int) bool

func (SuffixList) Swap

func (list SuffixList) Swap(i, j int)

Source Files

node.go

Version
v0.129.0 (latest)
Published
Dec 24, 2024
Platform
linux/amd64
Imports
5 packages
Last checked
1 day ago

Tools for package owners.