Skip to content

Filter

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),
)

Enables the filter and activates metrics collection.

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.

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.

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.

Like ShouldFilter but panics on error. For tests and benchmarks.

Returns whether the filter is active.

Returns a snapshot of detection statistics.

Returns the reasons this filter will detect.

Human-readable representation of the filter state.