Last Updated: May 22, 2026
go generate is a command that scans your source files for special //go:generate comments and runs whatever shell commands those comments name. It's not a build step, it's not a dependency manager, and it doesn't know anything about the tools it invokes. It exists so that the same workflow handles every code generator your project uses: stringer, mockgen, sqlc, protoc, oapi-codegen, whatever. This chapter covers the directive syntax, the environment it provides, the common generators you'll meet in e-commerce projects, and the workflow questions teams argue about (commit generated code or not, how to pin tool versions, when to use a Makefile instead).