Documentation ¶
Index ¶
- Constants
- func CheckGoModules() error
- func CheckGoProjectCmd(cmd *cobra.Command) error
- func CheckProjectRoot() error
- func CheckRepo(repo string) error
- func ExecCmd(cmd *exec.Cmd) error
- func GetGoPkg() string
- func GoBuild(opts GoCmdOptions) error
- func GoCmd(cmd string, opts GoCmdOptions) error
- func GoModOn() (bool, error)
- func GoTest(opts GoTestOptions) error
- func IsOperatorAnsible() bool
- func IsOperatorGo() bool
- func IsOperatorHelm() bool
- func MustGetGopath() string
- func MustGetwd() string
- func MustInProjectRoot()
- func MustSetWdGopath(currentGopath string) string
- func PrintDeprecationWarning(msg string)
- func SetGoVerbose() error
- func WdInGoPathSrc() (bool, error)
- type ErrUnknownOperatorType
- type GoCmdOptions
- type GoTestOptions
- type OperatorType
Constants ¶
const ( GoPathEnv = "GOPATH" GoFlagsEnv = "GOFLAGS" GoModEnv = "GO111MODULE" SrcDir = "src" )
Variables ¶
This section is empty.
Functions ¶
func CheckGoModules ¶ added in v0.12.0
func CheckGoModules() error
CheckGoModules ensures that go modules are enabled.
func CheckGoProjectCmd ¶ added in v0.5.0
func CheckProjectRoot ¶ added in v0.9.0
func CheckProjectRoot() error
CheckProjectRoot checks if the current dir is the project root, and returns an error if not. TODO(hasbro17): Change this to check for go.mod "build/Dockerfile" may not be present in all projects
func CheckRepo ¶ added in v0.12.0
CheckRepo ensures dependency manager type and repo are being used in combination correctly, as different dependency managers have different Go environment requirements.
func GetGoPkg ¶ added in v0.9.0
func GetGoPkg() string
TODO(hasbro17): If this function is called in the subdir of a module project it will fail to parse go.mod and return the correct import path. This needs to be fixed to return the pkg import path for any subdir in order for `generate csv` to correctly form pkg imports for API pkg paths that are not relative to the root dir. This might not be fixable since there is no good way to get the project root from inside the subdir of a module project.
GetGoPkg returns the current directory's import path by parsing it from wd if this project's repository path is rooted under $GOPATH/src, or from go.mod the project uses Go modules to manage dependencies. If the project has a go.mod then wd must be the project root.
Example: "github.com/example-inc/app-operator"
func GoBuild ¶ added in v0.8.0
func GoBuild(opts GoCmdOptions) error
GoBuild runs "go build" configured with opts.
func GoModOn ¶ added in v0.8.0
From https://github.com/golang/go/wiki/Modules:
You can activate module support in one of two ways: - Invoke the go command in a directory with a valid go.mod file in the current directory or any parent of it and the environment variable GO111MODULE unset (or explicitly set to auto). - Invoke the go command with GO111MODULE=on environment variable set.
GoModOn returns true if Go modules are on in one of the above two ways.
func GoTest ¶ added in v0.8.0
func GoTest(opts GoTestOptions) error
GoTest runs "go test" configured with opts.
func IsOperatorAnsible ¶ added in v0.8.0
func IsOperatorAnsible() bool
func IsOperatorGo ¶ added in v0.5.0
func IsOperatorGo() bool
func IsOperatorHelm ¶ added in v0.8.0
func IsOperatorHelm() bool
func MustGetGopath ¶ added in v0.5.0
func MustGetGopath() string
MustGetGopath gets GOPATH and ensures it is set and non-empty. If GOPATH is not set or empty, MustGetGopath exits.
func MustInProjectRoot ¶
func MustInProjectRoot()
MustInProjectRoot checks if the current dir is the project root, and exits if not.
func MustSetWdGopath ¶ added in v0.9.0
MustSetWdGopath sets GOPATH to the first element of the path list in currentGopath that prefixes the wd, then returns the set path. If GOPATH cannot be set, MustSetWdGopath exits.
func PrintDeprecationWarning ¶ added in v0.17.0
func PrintDeprecationWarning(msg string)
PrintDeprecationWarning prints a colored warning wrapping msg to the terminal.
func SetGoVerbose ¶ added in v0.8.0
func SetGoVerbose() error
SetGoVerbose sets GOFLAGS="${GOFLAGS} -v" if GOFLAGS does not already contain "-v" to make "go" command output verbose.
func WdInGoPathSrc ¶ added in v0.9.0
Types ¶
type ErrUnknownOperatorType ¶ added in v0.8.0
type ErrUnknownOperatorType struct {
Type string
}
func (ErrUnknownOperatorType) Error ¶ added in v0.8.0
func (e ErrUnknownOperatorType) Error() string
type GoCmdOptions ¶ added in v0.8.0
type GoCmdOptions struct { // BinName is the name of the compiled binary, passed to -o. BinName string // Args are args passed to "go {cmd}", aside from "-o {bin_name}" and // test binary args. // These apply to build, clean, get, install, list, run, and test. Args []string // PackagePath is the path to the main (go build) or test (go test) packages. PackagePath string // Env is a list of environment variables to pass to the cmd; // exec.Command.Env is set to this value. Env []string // Dir is the dir to run "go {cmd}" in; exec.Command.Dir is set to this value. Dir string }
GoCmdOptions is the base option set for "go" subcommands.
type GoTestOptions ¶ added in v0.8.0
type GoTestOptions struct { GoCmdOptions // TestBinaryArgs are args passed to the binary compiled by "go test". TestBinaryArgs []string }
GoTestOptions is the set of options for "go test".
type OperatorType ¶
type OperatorType = string
OperatorType - the type of operator
const ( // OperatorTypeGo - golang type of operator. OperatorTypeGo OperatorType = "go" // OperatorTypeAnsible - ansible type of operator. OperatorTypeAnsible OperatorType = "ansible" // OperatorTypeHelm - helm type of operator. OperatorTypeHelm OperatorType = "helm" // OperatorTypeUnknown - unknown type of operator. OperatorTypeUnknown OperatorType = "unknown" )
func GetOperatorType ¶
func GetOperatorType() OperatorType
GetOperatorType returns type of operator is in cwd. This function should be called after verifying the user is in project root.