mockgen has three modes of operation: archive, source and package. Source mode generates mock interfaces from a source file. It is enabled by using the -source flag. Other flags that may be useful in this mode are -imports, -aux_files and -exclude_interfaces. Example: mockgen -source=foo.go [other options] Package mode works by specifying the package and interface names. It is enabled by passing two non-flag arguments: an import path, and a comma-separated list of symbols. You can use "." to refer to the current path's package. Example: mockgen database/sql/driver Conn,Driver mockgen . SomeInterface Archive mode generates mock interfaces from a package archive file (.a). It is enabled by using the -archive flag and two non-flag arguments: an import path, and a comma-separated list of symbols. Example: mockgen -archive=pkg.a database/sql/driver Conn,Driver -archive string (archive mode) Input Go archive file; enables archive mode. -aux_files string (source mode) Comma-separated pkg=path pairs of auxiliary Go source files. -build_constraint string If non-empty, added as //go:build -build_flags string (package mode) Additional flags for go build. -copyright_file string Copyright file used to add copyright header -debug_parser Print out parser results only. -destination string Output file; defaults to stdout. -exclude_interfaces string Comma-separated names of interfaces to be excluded -exec_only string DEPRECATED (reflect mode) If set, execute this reflection program. -imports string (source mode) Comma-separated name=path pairs of explicit imports to use. -mock_names string Comma-separated interfaceName=mockName pairs of explicit mock names to use. Mock names default to 'Mock'+ interfaceName suffix. -model_gob string Skip package/source loading entirely and use the gob encoded model.Package at the given path -package string Package of the generated code; defaults to the package of the input with a 'mock_' prefix. -prog_only DEPRECATED (reflect mode) Only generate the reflection program; write it to stdout and exit. -self_package string The full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. This can happen if the mock's package is set to one of its inputs (usually the main one) and the output is stdio so mockgen cannot detect the final output package. Setting this flag will then tell mockgen which import to exclude. -source string (source mode) Input Go source file; enables source mode. -typed Generate Type-safe 'Return', 'Do', 'DoAndReturn' function -version Print version. -write_command_comment Writes the command used as a comment if true. (default true) -write_generate_directive Add //go:generate directive to regenerate the mock -write_package_comment Writes package documentation comment (godoc) if true. (default true) -write_source_comment Writes original file (source mode) or interface names (package mode) comment if true. (default true)