Skip to content

Pattern Matching

Include and exclude patterns support two wildcards:

PatternMeaning
*Matches any sequence of non-separator characters (single path segment)
**Matches zero or more complete path segments (crosses / boundaries)

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 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)
}
  • Patterns without / match against the filename only: *.pb.go matches any/path/user.pb.go
  • Patterns with / match against the full path: internal/*.go matches internal/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`
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.