Package generated provides a function that parses a Go file and reports whether it contains a "// Code generated … DO NOT EDIT." line comment.
It implements the specification at https://golang.org/s/generatedcode.
The first priority is correctness (no false negatives, no false positives). It must return accurate results even if the input Go source code is not gofmted.
The second priority is performance. The current version uses bufio.Reader and ReadBytes. Performance can be optimized further by using lower level I/O primitives and allocating less. That can be explored later. A lot of the time is spent on reading the entire file without being able to stop early, since the specification allows the comment to appear anywhere in the file.
go get dmitri.shuralyov.com/go/generated