Generating Go Code
Rob Pike (via David Nolen):
Programs that write programs are therefore important elements in software engineering, but programs like Yacc that produce source code need to be integrated into the build process so their output can be compiled. When an external build tool like Make is being used, this is usually easy to do. But in Go, whose go tool gets all necessary build information from the Go source, there is a problem. There is simply no mechanism to run Yacc from the go tool alone.
Until now, that is.
The latest Go release, 1.4, includes a new command that makes it easier to run such tools. It’s called
go
generate
, and it works by scanning for special comments in Go source code that identify general commands to run. It’s important to understand thatgo
generate
is not part ofgo
build
. It contains no dependency analysis and must be run explicitly before runninggo
build
. It is intended to be used by the author of the Go package, not its clients.