Filter
Constructor
Section titled “Constructor”NewFilter(configs ...FilterConfig) (*Filter, error)
Section titled “NewFilter(configs ...FilterConfig) (*Filter, error)”Creates a new filter with functional options. The filter is immutable after construction.
opts, err := gogenfilter.WithFilterOptions(gogenfilter.FilterAll)if err != nil { // handle error}f, err := gogenfilter.NewFilter(opts)if err != nil { // handle error}Functional Options
Section titled “Functional Options”WithFilterOptions(opts ...FilterOption) (FilterConfig, error)
Section titled “WithFilterOptions(opts ...FilterOption) (FilterConfig, error)”Specifies which generators to detect. Returns an error with *FilterConfigError for 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”Filter(filePath string) (bool, error)
Section titled “Filter(filePath string) (bool, error)”Determines if a file should be filtered. Returns true if the file is generated. I/O errors propagate.
FilterDetailed(filePath string) (FilterResult, error)
Section titled “FilterDetailed(filePath string) (FilterResult, error)”Like Filter but returns a FilterResult with detailed reason and trace information.
result, err := f.FilterDetailed("db/models.go")if result.Filtered { fmt.Println(result.Reason, result.Trace)}FilterPaths(paths []string) ([]bool, error)
Section titled “FilterPaths(paths []string) ([]bool, error)”Batch filters multiple file paths, returning a slice of booleans. Returns partial results and the error if any path fails.
results, err := f.FilterPaths([]string{"a.go", "b.go", "c.go"})// results: [true, false, true] — a.go and c.go are generatedFilterPathsDetailed(paths []string) ([]FilterResult, error)
Section titled “FilterPathsDetailed(paths []string) ([]FilterResult, error)”Batch variant of FilterDetailed — returns FilterResult values with trace information for each path.
IsEnabled() bool
Section titled “IsEnabled() bool”Returns whether the filter is active.
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.