liveBook · Manning

Go generate

go generate is a Go command that executes source-generation directives embedded in Go source files to produce source code or other files.

How 2 Manning books explain it

Go in Practice, Second Edition

go generate is a Go command that executes source-code generation directives embedded in Go files.

How it is used
Runs source-file directives that generate repetitive, type-safe Go declarations when generics are not applicable or reflection is undesirable.
How deep it goes
Works through directive syntax, a template-based generator, generated queue usage, and shell commands.
Examples
Uses an echo directive and a typed queue generator that writes a `_queue.go` file.
What you can do after
Build it from scratch as a template-based queue generator and run `go generate` before compiling its output.

Read how Go in Practice, Second Edition explains go generate →

Learn Go with Pocket-Sized Projects

go generate is a Go command that executes source-code generation directives found in comments.

How it is used
Automates repeatable source generation for Go projects, especially gRPC APIs defined with Protocol Buffers.
How deep it goes
Explains directives, shell wildcard limitations, command placement, and output paths, but stops short of general generator design.
Examples
Uses generate.go, protoc commands, *.proto inputs, source-relative paths, and a generated project tree.
What you can do after
Operate/configure repeatable gRPC code generation through a documented //go:generate directive or maintained build command.

Read how Learn Go with Pocket-Sized Projects explains go generate →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.