glob

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package glob matches slash-separated paths against patterns with `*`, `?`, `[...]`, and the `**` segment that spans directories.

Why not path.Match: the standard library has no `**`, and every config in docsync (`scan.code`, `scan.docs`, `exclude`, `generated`, `secret`, `run.allow`, `policy.require_doc`) is written with it. Why not a dependency: the root module is stdlib-only by design (docs/SPEC.md §37.1).

Semantics, chosen to match what people expect from gitignore-style tools:

  • `*` and `?` never match `/`.
  • `**` as a whole segment matches zero or more segments: `a/**/b` matches `a/b`, `a/x/b`, `a/x/y/b`. A trailing `**` matches everything below the directory (at least one more segment), never the directory path itself.
  • `**` inside a segment (`a**b`) is treated as two stars, i.e. `*`.
  • Patterns and paths are compared as-is; callers normalize separators and case before calling. Paths are relative and never start with `/`.
  • A pattern with no `/` matches only a single-segment path (`*.go` does not match `dir/x.go`); use `**/*.go` for any depth. This is deliberate: it keeps `README.md` in `scan.docs` from matching every README.

Index

Constants

This section is empty.

Variables

View Source
var ErrBadPattern = errors.New("glob: bad pattern")

ErrBadPattern is returned by Match and Compile for a malformed bracket class.

Functions

func Match

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

Match reports whether name matches pattern. It is equivalent to Compile(pattern) followed by Pattern.Match but validates on every call, so hot loops should compile once.

Types

type Pattern

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

Pattern is a compiled glob. Zero value matches nothing.

func Compile

func Compile(pattern string) (Pattern, error)

Compile validates pattern and prepares it for repeated matching. Each segment is checked with path.Match against a probe so bracket errors surface here rather than silently never matching.

func (Pattern) Match

func (p Pattern) Match(name string) bool

Match reports whether name matches. name uses `/` separators and no leading slash. An empty name never matches.

func (Pattern) String

func (p Pattern) String() string

String returns the pattern source.

type Set

type Set []Pattern

Set is an ordered list of compiled patterns; MatchAny answers "does any pattern match", which is how every include and exclude list in the config is consulted.

func CompileAll

func CompileAll(patterns []string) (Set, error)

CompileAll compiles every pattern or returns the first error with the offending pattern in the message.

func (Set) MatchAny

func (s Set) MatchAny(name string) bool

MatchAny reports whether any pattern in the set matches name. An empty set matches nothing, so an empty include list scans nothing and an empty exclude list excludes nothing — the safe defaults.

Jump to

Keyboard shortcuts

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