Skip to content

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

Matches a path against a glob pattern using doublestar. Supports * (single segment) and ** (any depth).

gogenfilter.MatchPattern("pkg/mocks/service.go", "**/mocks/*.go") // true

Each generator has dedicated Is*Generated(filePath, content string) bool functions:

FunctionChecks
IsSQLCGeneratedFilename + content markers
IsTemplGenerated_templ.go suffix + templ.Component
IsGoEnumGenerated_enum.go suffix + content
IsProtobufGenerated.pb.go / _grpc.pb.go + content
IsOapiGeneratedoapi-codegen content marker
IsDeepcopyGeneratedContent marker (deepcopy-gen)
IsWireGeneratedContent marker (Wire)
IsMoqGeneratedContent marker (moq)
IsMockgenGeneratedContent marker (MockGen)
IsStringerGeneratedContent marker ("stringer")
IsGenericGeneratedAny 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 standalone Is*Generated functions check both filename and content where applicable. For the full two-phase detection pipeline with all generators at once, use Filter or DetectReason.