Pattern Matching
Wildcards
Section titled “Wildcards”Include and exclude patterns support two wildcards:
| Pattern | Meaning |
|---|---|
* | Matches any sequence of non-separator characters (single path segment) |
** | Matches zero or more complete path segments (crosses / boundaries) |
Include Patterns
Section titled “Include Patterns”Include patterns restrict scope: only files matching at least one include pattern are checked. All other files are immediately filtered (skipped).
opts, err := gogenfilter.WithFilterOptions(gogenfilter.FilterAll)if err != nil { panic(err)}includeConfig := gogenfilter.WithIncludePatterns("pkg/**")f, err := gogenfilter.NewFilter(opts, includeConfig)if err != nil { panic(err)}Files outside pkg/ are filtered with ReasonOutsideScope.
Exclude Patterns
Section titled “Exclude Patterns”Exclude patterns broaden scope: matching files are always filtered, regardless of detection.
opts, err := gogenfilter.WithFilterOptions(gogenfilter.FilterAll)if err != nil { panic(err)}excludeConfig := gogenfilter.WithExcludePatterns("**/*.pb.go", "mocks/*")f, err := gogenfilter.NewFilter(opts, excludeConfig)if err != nil { panic(err)}Pattern Rules
Section titled “Pattern Rules”- Patterns without
/match against the filename only:*.pb.gomatchesany/path/user.pb.go - Patterns with
/match against the full path:internal/*.gomatchesinternal/handler.go **/at the start matches at any depth:`\*_/mocks/_.go`matches`pkg/mocks/service.go`/**at the end matches anything under a directory:`generated/\*\*`matches`generated/a/b/c.go`/**/in the middle bridges any number of segments:`src/\*\*/test.go`matches`src/pkg/test.go`
Combined Example
Section titled “Combined Example”opts, err := gogenfilter.WithFilterOptions(gogenfilter.FilterAll)if err != nil { panic(err)}includeConfig := gogenfilter.WithIncludePatterns("pkg/**")excludeConfig := gogenfilter.WithExcludePatterns("**/*.pb.go")f, err := gogenfilter.NewFilter(opts, includeConfig, excludeConfig)if err != nil { panic(err)}This filters everything inside pkg/ except protobuf files, which are excluded regardless.