glob

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(pattern, path string) (bool, error)

Match reports whether path matches the glob pattern. The pattern supports ** (recursive wildcard), * (single-level wildcard), ? (single character), and [...] (character classes). The path must use forward slashes.

For repeated matches against the same pattern, prefer Compile + Matcher.Match to avoid recompiling the regular expression on every call.

Types

type Matcher

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

Matcher is a precompiled glob pattern that can be matched against many paths without recompiling the underlying regular expression. Create one with Compile and reuse it across many Match calls.

func Compile

func Compile(pattern string) (*Matcher, error)

Compile compiles a glob pattern into a reusable Matcher. The pattern supports ** (recursive wildcard), * (single-level wildcard), ? (single character), and [...] (character classes). A trailing "/" marks the pattern as directory-only (gitignore semantics): the slash is stripped and IsDirOnly returns true so callers can skip non-directory entries. The path passed to Matcher.Match must use forward slashes.

func (*Matcher) IsDirOnly

func (m *Matcher) IsDirOnly() bool

IsDirOnly reports whether the pattern was suffixed with "/" (gitignore directory-only semantics). Callers should skip non-directory entries when this returns true.

func (*Matcher) Match

func (m *Matcher) Match(path string) bool

Match reports whether path matches the precompiled pattern. The path must use forward slashes.

func (*Matcher) Pattern

func (m *Matcher) Pattern() string

Pattern returns the original glob pattern the Matcher was compiled from. If the pattern had a trailing "/", it is stripped; use IsDirOnly to check.

Jump to

Keyboard shortcuts

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