Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Glob ¶
func Glob(ctx context.Context, dir string, matcher Matcher, opts ...GlobOption) (map[string]os.FileInfo, error)
Glob returns the pathnames and their associated os.FileInfos of all files matching with the Matcher provided.
Patterns are matched against the path relative to the directory provided and path seperators are converted to '/'. Be aware that the matching performed by this library's Matchers are case sensitive (even on case-insensitive filesystems). Use WithPathTransformer(strings.ToLower) and NewMatcher(strings.ToLower(pattern)) to perform case-insensitive matching.
Glob ignores any permission and I/O errors.
func Match ¶
func Match(pattern, pathname string, opts ...MatchOption) (bool, error)
Match has similar behaviour to path.Match, but supports globstar.
The pattern term '**' in a path portion matches zero or more subdirectories.
The only possible returned error is ErrBadPattern, when the pattern is malformed.
Types ¶
type GlobOption ¶
type GlobOption func(*globOptions) error
GlobOption is an option to configure Glob() behaviour.
func WithPathTransformer ¶
func WithPathTransformer(transformer func(pathname string) string) GlobOption
WithPathTransforms allows a function to transform a path prior to it being matched. A common use-case is WithPathTransformer(strings.ToLower) to ensure paths have their case folded before matching.
The transformer function should be safe for concurrent use.
type MatchOption ¶
type MatchOption func(*matchOptions)
MatchOption is an option to configure Match() behaviour.
func WithMatchFunc ¶
func WithMatchFunc(matcher func(pattern, name string) (matched bool, err error)) MatchOption
WithMatchFunc allows a user provided matcher to be used in place of path.Match for matching path segments. The globstar pattern will always be supported, but paths between directory separators will be matched against the function provided.
type Matcher ¶
Matcher is an interface used for matching a path against a pattern.
func New ¶
func New(pattern string, opts ...MatchOption) Matcher
New returns a new Matcher.
The Matcher returned uses the same rules as Match, but returns a result of either NotMatched, Matched or Follow.
Follow hints to the caller that whilst the pattern wasn't matched, path traversal might yield matches. This allows for more efficient globbing, preventing path traversal where a match is impossible.