Detection
Combined Detection
Section titled “Combined Detection”DetectReason(filePath, content string, opts ...FilterOption) FilterReason
Section titled “DetectReason(filePath, content string, opts ...FilterOption) FilterReason”Checks if a file is auto-generated based on filename and content. No I/O — you provide the content. Returns the reason or ReasonNotFiltered.
reason := gogenfilter.DetectReason("db/models.go", content, gogenfilter.FilterSQLC, gogenfilter.FilterGeneric,)DetectReasonReader(filePath string, r io.Reader, opts ...FilterOption) (FilterReason, error)
Section titled “DetectReasonReader(filePath string, r io.Reader, opts ...FilterOption) (FilterReason, error)”Same as DetectReason but reads from an io.Reader.
r := bytes.NewBufferString(content)reason, err := gogenfilter.DetectReasonReader("file.go", r, opts...)Pattern Matching
Section titled “Pattern Matching”MatchPattern(path, pattern string) bool
Section titled “MatchPattern(path, pattern string) bool”Matches a path against a glob pattern using doublestar. Supports * (single segment) and ** (any depth).
gogenfilter.MatchPattern("pkg/mocks/service.go", "**/mocks/*.go") // truePer-Generator Detection
Section titled “Per-Generator Detection”Each generator has dedicated Is*Generated(filePath, content string) bool functions:
| Function | Checks |
|---|---|
IsSQLCGenerated | Filename + content markers |
IsTemplGenerated | _templ.go suffix + templ.Component |
IsGoEnumGenerated | _enum.go suffix + content |
IsProtobufGenerated | .pb.go / _grpc.pb.go + content |
IsOapiGenerated | oapi-codegen content marker |
IsDeepcopyGenerated | Content marker (deepcopy-gen) |
IsWireGenerated | Content marker (Wire) |
IsMoqGenerated | Content marker (moq) |
IsMockgenGenerated | Content marker (MockGen) |
IsStringerGenerated | Content marker ("stringer") |
IsGenericGenerated | Any Code generated by comment |
Note: Some generators use filename patterns (e.g.,
wire_gen.go,_moq.go,zz_generated.*) as a first pass, but the standaloneIs*Generatedfunctions check both filename and content where applicable. For the full two-phase detection pipeline with all generators at once, useFilterorDetectReason.