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

f := gogenfilter.NewFilter(
gogenfilter.Enabled(),
gogenfilter.WithFilterOptions(gogenfilter.FilterAll),
gogenfilter.WithIncludePatterns("pkg/**"),
)

Files outside pkg/ are filtered with ReasonIncludePattern.

Exclude patterns broaden scope: matching files are always filtered, regardless of detection.

f := gogenfilter.NewFilter(
gogenfilter.Enabled(),
gogenfilter.WithFilterOptions(gogenfilter.FilterAll),
gogenfilter.WithExcludePatterns("**/*.pb.go", "mocks/*"),
)
  • 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/_.gomatchespkg/mocks/service.go
  • /** at the end matches anything under a directory: generated/\*\*matchesgenerated/a/b/c.go
  • /**/ in the middle bridges any number of segments: src/\*\*/test.gomatchessrc/pkg/test.go
f := gogenfilter.NewFilter(
gogenfilter.Enabled(),
gogenfilter.WithFilterOptions(gogenfilter.FilterAll),
gogenfilter.WithIncludePatterns("pkg/**"),
gogenfilter.WithExcludePatterns("**/*.pb.go"),
)

This filters everything inside pkg/ except protobuf files, which are excluded regardless.