Documentation
¶
Index ¶
- Constants
- Variables
- func CheckDepManagerWithRepo(dm DepManagerType, repo string) error
- func CheckGoProjectCmd(cmd *cobra.Command) error
- func CheckProjectRoot() 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 IsDepManagerDep() bool
- func IsDepManagerGoMod() bool
- func IsOperatorAnsible() bool
- func IsOperatorGo() bool
- func IsOperatorHelm() bool
- func MustGetGopath() string
- func MustGetwd() string
- func MustInProjectRoot()
- func MustSetWdGopath(currentGopath string) string
- func SetGoVerbose() error
- func WdInGoPathSrc() (bool, error)
- type DepManagerType
- type ErrInvalidDepManager
- type ErrUnknownOperatorType
- type GoCmdOptions
- type GoTestOptions
- type OperatorType
Constants ¶
const ( GoPathEnv = "GOPATH" GoFlagsEnv = "GOFLAGS" GoModEnv = "GO111MODULE" SrcDir = "src" )
Variables ¶
var ErrNoDepManager = fmt.Errorf(`no valid dependency manager file found; dep manager must be one of ["%v", "%v"]`, DepManagerDep, DepManagerGoMod)
Functions ¶
func CheckDepManagerWithRepo ¶
func CheckDepManagerWithRepo(dm DepManagerType, repo string) error
CheckDepManagerWithRepo ensures dependency manager type and repo are being used in combination correctly, as different dependency managers have different Go environment requirements.
func CheckGoProjectCmd ¶
func CheckProjectRoot ¶
func CheckProjectRoot() error
CheckProjectRoot checks if the current dir is the project root, and returns an error if not.
func GetGoPkg ¶
func GetGoPkg() string
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.
Example: "github.com/example-inc/app-operator"
func GoModOn ¶
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 outside of the $GOPATH/src tree, 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 IsDepManagerDep ¶
func IsDepManagerDep() bool
func IsDepManagerGoMod ¶
func IsDepManagerGoMod() bool
func IsOperatorAnsible ¶
func IsOperatorAnsible() bool
func IsOperatorGo ¶
func IsOperatorGo() bool
func IsOperatorHelm ¶
func IsOperatorHelm() bool
func MustGetGopath ¶
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 ¶
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 SetGoVerbose ¶
func SetGoVerbose() error
SetGoVerbose sets GOFLAGS="${GOFLAGS} -v" if GOFLAGS does not already contain "-v" to make "go" command output verbose.
func WdInGoPathSrc ¶
Types ¶
type DepManagerType ¶
type DepManagerType string
const ( DepManagerGoMod DepManagerType = "modules" DepManagerDep DepManagerType = "dep" )
func GetDepManagerType ¶
func GetDepManagerType() (DepManagerType, error)
type ErrInvalidDepManager ¶
type ErrInvalidDepManager string
func (ErrInvalidDepManager) Error ¶
func (e ErrInvalidDepManager) Error() string
type ErrUnknownOperatorType ¶
type ErrUnknownOperatorType struct {
Type string
}
func (ErrUnknownOperatorType) Error ¶
func (e ErrUnknownOperatorType) Error() string
type GoCmdOptions ¶
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 // GoMod determines whether to set the "-mod=vendor" flag. // If true and ./vendor/ exists, "go {cmd}" will use vendored modules. // If false, "go {cmd}" will not use Go modules. This is the default. // This applies to build, clean, get, install, list, run, and test. GoMod bool }
GoCmdOptions is the base option set for "go" subcommands.
type GoTestOptions ¶
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.