LinuxCommandLibrary

go-generate

run code generation directives in Go source files

TLDR

Run generators in current package

$ go generate
copy
Run generators in all packages
$ go generate ./...
copy
Run specific generator by pattern
$ go generate -run [pattern]
copy
Preview commands without executing
$ go generate -n
copy
Run with verbose output
$ go generate -v
copy
Skip generators matching pattern
$ go generate -skip [pattern]
copy

SYNOPSIS

go generate [-run regexp] [-skip regexp] [-n] [-v] [-x] [packages]

DESCRIPTION

go generate scans Go source files for special directives of the form //go:generate command and executes the specified command. It automates code generation before compilation, commonly used for creating string methods, mock implementations, protocol buffers, and other generated code. Directives must start at the beginning of a line with no space between // and go:generate.

PARAMETERS

-run regexp

Run only directives matching regexp.
-skip regexp
Skip directives matching regexp.
-n
Print commands without executing.
-v
Print package names as processed.
-x
Print commands as executed.

CAVEATS

Environment variables $GOFILE, $GOLINE, $GOPACKAGE, and $GOROOT are set during execution. Generated files should include a comment matching **^// Code generated .* DO NOT EDIT\.$** before non-comment content.

SEE ALSO

go(1), go-build(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community