go generate

AI-generated

go generate runs commands declared by //go:generate directives. It is an explicit developer tool: it is not run automatically by go build, go test, or module download.

package status

//go:generate stringer -type=State

type State int

const (
    Pending State = iota
    Running
    Done
)

Run every directive in the current package:

go generate

Run directives recursively for packages in the module:

go generate ./...

The generator executable must already be installed and available on PATH.

Reproducible generation

AI-generated

  • Pin generator versions in normal module tooling or a documented tool setup.
  • Commit generated files when consumers should not need the generator.
  • Put a “generated; do not edit” comment in generated output.
  • Make generation deterministic; avoid timestamps and machine-specific paths.
  • In CI, regenerate and fail if git diff --exit-code reports a change.
  • Review generated code like dependency output: generators execute with the developer's permissions.

Further reading: Generating code.