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

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
IsDeepcopyGeneratedzz_generated.* + content
IsWireGeneratedwire_gen.go + content
IsMoqGenerated_moq.go + content
IsMockgenGenerated_mock.go / mock_ + content
IsStringerGeneratedContent marker
IsGenericGeneratedAny Code generated by comment

Zero-I/O filename checks:

gogenfilter.MatchesSQLCFilename("db/query.sql.go") // true
gogenfilter.HasSQLCContent(content)
gogenfilter.HasSQLCCodePatterns(content)