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

DetectReasonFile(filePath string, opts ...FilterOption) (FilterReason, error)

Section titled “DetectReasonFile(filePath string, opts ...FilterOption) (FilterReason, error)”

Checks if a file is auto-generated using two-phase detection in a single call. Phase 1 checks filename patterns (zero I/O). Phase 2 reads the file for content-based detection only if needed. Uses the OS filesystem (os.DirFS(".")).

reason, err := gogenfilter.DetectReasonFile("db/models.go",
gogenfilter.FilterSQLC,
gogenfilter.FilterGeneric,
)

DetectReasonFileFS(fsys fs.FS, filePath string, opts ...FilterOption) (FilterReason, error)

Section titled “DetectReasonFileFS(fsys fs.FS, filePath string, opts ...FilterOption) (FilterReason, error)”

Same as DetectReasonFile but with a custom filesystem.

reason, err := gogenfilter.DetectReasonFileFS(fsys, "db/models.go",
gogenfilter.FilterSQLC,
)

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:

Function Checks
IsSQLCGenerated models.go, querier.go, query.sql.go, batch.go, *.sql.go + content
IsTemplGenerated _templ.go suffix + content
IsGoEnumGenerated _enum.go suffix + content
IsProtobufGenerated .pb.go, _grpc.pb.go suffix + content
IsOapiGenerated Content marker (oapi-codegen)
IsDeepcopyGenerated zz_generated.* prefix + .go suffix + content
IsWireGenerated wire_gen.go suffix + content
IsMoqGenerated _moq.go, _moq_test.go suffix + content
IsMockgenGenerated _mock.go suffix + content
IsStringerGenerated Content marker (stringer)
IsMockeryGenerated mock_ prefix + content
IsEntGenerated Content marker (ent)
IsGqlgenGenerated Content marker (gqlgen)
IsEasyjsonGenerated _easyjson.go suffix + content
IsMsgpGenerated Content marker (msgp)
IsCounterfeiterGenerated fake_ prefix + content
IsGoSwaggerGenerated Content marker (go-swagger)
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 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.