Documentation
¶
Overview ¶
Package filter provides file filtering for sync operations.
Filters are used to include or exclude files based on patterns, size, and age. They are inspired by rclone's filtering system.
Basic usage:
f := filter.New(
filter.Include("*.json"),
filter.Exclude("*.tmp"),
filter.MaxSize(100 * 1024 * 1024), // 100 MB
)
if f.Match(fileInfo) {
// File passes filter
}
Index ¶
Constants ¶
const ( KB = 1024 MB = 1024 * KB GB = 1024 * MB TB = 1024 * GB )
Common file size constants for convenience.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter determines whether files should be included in sync operations.
func (*Filter) Match ¶
Match returns true if the file passes the filter.
The filtering logic:
- If there are include patterns and the file doesn't match any, exclude it
- If the file matches any exclude pattern, exclude it
- If the file fails size or age constraints, exclude it
- Otherwise, include the file
type Option ¶
type Option func(*Filter)
Option configures a Filter.
func Exclude ¶
Exclude adds an exclude pattern. Files matching any exclude pattern are excluded. Exclude rules take precedence over include rules.
func FromFile ¶
FromFile loads filter rules from a file. Each line is a pattern. Lines starting with + are includes, lines starting with - are excludes. Empty lines and lines starting with # are ignored.
Example file:
# Include JSON files + *.json # Exclude temp files - *.tmp - *.bak
func Include ¶
Include adds an include pattern. Files matching any include pattern are included (unless excluded). Patterns use filepath.Match syntax (*, ?, [...]).
func MaxAge ¶
MaxAge sets the maximum file age filter. Files older than this are excluded. Age is calculated as time since modification.