How to Use go generate in Go

Run go generate to execute commands defined in //go:generate comments within your Go source files.

Use go generate to run commands specified in //go:generate comments within your Go source files. Add a comment like //go:generate go run gen.go above your package declaration, then execute the command:

go generate

This command scans the current directory and subdirectories for //go:generate directives and executes them in order.