Skip to content

Filter

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
}

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.

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.

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 generated

FilterPathsDetailed(paths []string) ([]FilterResult, error)

Section titled “FilterPathsDetailed(paths []string) ([]FilterResult, error)”

Batch variant of FilterDetailed — returns FilterResult values with trace information for each path.

Returns whether the filter is active.

Returns the reasons this filter will detect.

Human-readable representation of the filter state.