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 ¶
var ErrBadPattern = errors.New("glob: bad pattern")
ErrBadPattern is returned by Match and Compile for a malformed bracket class.
Functions ¶
Types ¶
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
Pattern is a compiled glob. Zero value matches nothing.
func Compile ¶
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.
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 ¶
CompileAll compiles every pattern or returns the first error with the offending pattern in the message.