Documentation
¶
Overview ¶
Package filter implements filters for files similar to filepath.Glob, but in contrast to filepath.Glob a pattern may specify directories.
For a list of valid patterns please see the documentation on filepath.Glob.
Index ¶
- Variables
- func ChildMatch(patternStr, str string) (matched bool, err error)
- func List(patterns []Pattern, str string) (matched bool, err error)
- func ListWithChild(patterns []Pattern, str string) (matched bool, childMayMatch bool, err error)
- func Match(patternStr, str string) (matched bool, err error)
- func ValidatePatterns(patterns []string) error
- type InvalidPatternError
- type Pattern
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBadString = errors.New("filter.Match: string is empty")
ErrBadString is returned when Match is called with the empty string as the second argument.
Functions ¶
func ChildMatch ¶
ChildMatch returns true if children of str can match the pattern. When the pattern is malformed, filepath.ErrBadPattern is returned. The empty pattern matches everything, when str is the empty string ErrBadString is returned.
Pattern can be a combination of patterns suitable for filepath.Match, joined by filepath.Separator.
In addition patterns suitable for filepath.Match, pattern accepts a recursive wildcard '**', which greedily matches an arbitrary number of intermediate directories.
func List ¶
List returns true if str matches one of the patterns. Empty patterns are ignored.
Example ¶
package main import ( "fmt" "github.com/wutong-paas/restic/pkg/filter" ) func main() { patterns := filter.ParsePatterns([]string{"*.c", "*.go"}) match, _ := filter.List(patterns, "/home/user/file.go") fmt.Printf("match: %v\n", match) }
Output: match: true
func ListWithChild ¶
ListWithChild returns true if str matches one of the patterns. Empty patterns are ignored.
func Match ¶
Match returns true if str matches the pattern. When the pattern is malformed, filepath.ErrBadPattern is returned. The empty pattern matches everything, when str is the empty string ErrBadString is returned.
Pattern can be a combination of patterns suitable for filepath.Match, joined by filepath.Separator.
In addition patterns suitable for filepath.Match, pattern accepts a recursive wildcard '**', which greedily matches an arbitrary number of intermediate directories.
Example ¶
package main import ( "fmt" "github.com/wutong-paas/restic/pkg/filter" ) func main() { match, _ := filter.Match("*.go", "/home/user/file.go") fmt.Printf("match: %v\n", match) }
Output: match: true
Example (Wildcards) ¶
package main import ( "fmt" "github.com/wutong-paas/restic/pkg/filter" ) func main() { match, _ := filter.Match("/home/[uU]ser/?.go", "/home/user/F.go") fmt.Printf("match: %v\n", match) }
Output: match: true
func ValidatePatterns ¶
ValidatePatterns validates a slice of patterns. Returns true if all patterns are valid - false otherwise, along with the invalid patterns.
Types ¶
type InvalidPatternError ¶
type InvalidPatternError struct {
InvalidPatterns []string
}
func (*InvalidPatternError) Error ¶
func (e *InvalidPatternError) Error() string