pathmatch

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pathmatch matches slash-separated paths against glob patterns.

The syntax is path.Match applied per segment, plus "**" for "zero or more path segments". path.Match alone cannot express "**" — its "*" never crosses a separator — so the segment walk lives here rather than being open-coded by each caller.

The package is deliberately independent of the repository model: it matches strings. `find` uses it for -name/-path patterns, and it is the intended home for backup exclude patterns, which need the same syntax.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPathPattern

func IsPathPattern(pattern string) bool

IsPathPattern reports whether the pattern constrains more than a basename. A caller deciding between matching a name and matching a full path uses this to make that choice from the pattern alone.

Types

type Pattern

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

Pattern is a compiled glob.

func Compile

func Compile(pattern string, ignoreCase bool) (*Pattern, error)

Compile parses a glob pattern. When ignoreCase is set, both the pattern and every candidate are folded to lower case before matching — which is a property of the *match*, not a claim about the case sensitivity of the filesystem the files came from.

func (*Pattern) BaseSegment

func (p *Pattern) BaseSegment() (*Pattern, bool)

BaseSegment returns the pattern's last segment when that segment can serve as a cheap basename prefilter — that is, when it is not "**", which matches any number of segments and therefore constrains the basename not at all.

This is what makes "Documents/**/*.pdf" affordable: the caller evaluates "*.pdf" against a name it already holds and resolves the full path only for the entries that survive. A pattern ending in "**" has no such prefilter, and the caller has to resolve every path.

func (*Pattern) Match

func (p *Pattern) Match(s string) bool

Match reports whether s matches the pattern. s is treated as a slash-separated path; leading and trailing slashes are ignored.

func (*Pattern) String

func (p *Pattern) String() string

String returns the pattern as written.

Jump to

Keyboard shortcuts

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