Filter
Constructor
Section titled “Constructor”NewFilter(configs ...FilterConfig) *Filter
Section titled “NewFilter(configs ...FilterConfig) *Filter”Creates a new filter with functional options. The filter is immutable after construction.
f := gogenfilter.NewFilter( gogenfilter.Enabled(), gogenfilter.WithFilterOptions(gogenfilter.FilterAll),)Functional Options
Section titled “Functional Options”Enabled() FilterConfig
Section titled “Enabled() FilterConfig”Enables the filter and activates metrics collection.
Disabled() FilterConfig
Section titled “Disabled() FilterConfig”Disables the filter. All calls to ShouldFilter return false.
WithFilterOptions(opts ...FilterOption) FilterConfig
Section titled “WithFilterOptions(opts ...FilterOption) FilterConfig”Specifies which generators to detect. Panics on invalid options.
WithFS(fsys fs.FS) FilterConfig
Section titled “WithFS(fsys fs.FS) FilterConfig”Sets a custom filesystem. Defaults to os.DirFS(".").
WithIncludePatterns(patterns ...string) FilterConfig
Section titled “WithIncludePatterns(patterns ...string) FilterConfig”Restricts scope to files matching at least one pattern.
WithExcludePatterns(patterns ...string) FilterConfig
Section titled “WithExcludePatterns(patterns ...string) FilterConfig”Files matching any pattern are always filtered.
Methods
Section titled “Methods”ShouldFilter(filePath string) (bool, error)
Section titled “ShouldFilter(filePath string) (bool, error)”Determines if a file should be filtered. Returns true if the file is generated. I/O errors propagate.
MustShouldFilter(filePath string) bool
Section titled “MustShouldFilter(filePath string) bool”Like ShouldFilter but panics on error. For tests and benchmarks.
IsEnabled() bool
Section titled “IsEnabled() bool”Returns whether the filter is active.
GetStats() FilterStats
Section titled “GetStats() FilterStats”Returns a snapshot of detection statistics.
FilterReasons() []FilterReason
Section titled “FilterReasons() []FilterReason”Returns the reasons this filter will detect.
String() string
Section titled “String() string”Human-readable representation of the filter state.