Documentation
¶
Overview ¶
Package gogen contains various useful functions for creating Go source code files.
Index ¶
- func AddParams(fileName *string, makeFile *bool) func(ps *param.PSet) error
- func ExecGoCmd(ioMode CmdIOType, args ...string)
- func ExecGoCmdCaptureOutput(w io.Writer, args ...string)
- func GetGopath() string
- func GetImportPath() (string, error)
- func GetImportPathOrDie() string
- func GetModule() (string, error)
- func GetModuleOrDie() string
- func GetPackage() (string, error)
- func GetPackageOrDie() string
- func MakeFileOrDie(filename string) *os.File
- func MakeTestFileOrDie(filename string) *os.File
- func PrintImports(f io.Writer, imps ...string)
- func PrintPreambleOrDie(f io.Writer, ps *param.PSet)
- type CmdIOType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddParams ¶ added in v1.2.0
AddParams will add standard parameters to the passed ParamSet.
Note that if the filename has no default value then the filename parameter must be set if the file is to be created (if, after parameters are set, makeFile is true). If it does have a value then the option will not be shown in the standard (abridged) help message.
Note also that the makeFile parameter must be set to true. This will panic if it is false.
func ExecGoCmd ¶ added in v1.4.0
ExecGoCmd will exec the go program with the supplied arguments. If it detects an error it will report it and exit
func ExecGoCmdCaptureOutput ¶ added in v1.7.0
ExecGoCmdCaptureOutput will exec the go program with the supplied arguments. The command's Stdout is connected to the supplied writer if it is not nil.
func GetGopath ¶ added in v1.7.0
func GetGopath() string
GetGopath returns the value of the GOPATH variable
func GetImportPath ¶
GetImportPath returns the import path of the current package.
func GetImportPathOrDie ¶ added in v1.1.0
func GetImportPathOrDie() string
GetImportPathOrDie returns the import path of the current package. Any failure will cause the program to exit.
func GetModuleOrDie ¶ added in v1.6.0
func GetModuleOrDie() string
GetModuleOrDie returns the name of the current module. Any failure will cause the program to exit.
func GetPackage ¶
GetPackage returns the name of the current package.
func GetPackageOrDie ¶ added in v1.1.0
func GetPackageOrDie() string
GetPackageOrDie returns the name of the current package. Any failure will cause the program to exit.
func MakeFileOrDie ¶
MakeFileOrDie creates the file truncating it if it already exists and returning the open file. If an error is detected, it is reported and the program exits. It also checks that the file is a go file and does not have the _test.go suffix.
func MakeTestFileOrDie ¶ added in v1.3.0
MakeTestFileOrDie creates the file truncating it if it already exists and returning the open file. If an error is detected, it is reported and the program exits. It also checks that the file has the _test.go suffix.
func PrintImports ¶ added in v1.2.0
PrintImports adds the import statements, if any, one per line to the file
func PrintPreambleOrDie ¶ added in v1.1.0
PrintPreambleOrDie prints the introductory comments for the file to be generated. Note that the package name is written when the file is created; this is because the go list command fails if any go file is empty when it runs.