projutil

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GoPathEnv  = "GOPATH"
	GoFlagsEnv = "GOFLAGS"
	GoModEnv   = "GO111MODULE"
	SrcDir     = "src"
)

Variables

View Source
var ErrNoDepManager = fmt.Errorf(`no valid dependency manager file found; dep manager must be one of ["%v", "%v"]`, DepManagerDep, DepManagerGoMod)

Functions

func CheckAndGetProjectGoPkg added in v0.2.0

func CheckAndGetProjectGoPkg() string

CheckAndGetProjectGoPkg checks if this project's repository path is rooted under $GOPATH and returns the current directory's import path e.g: "github.com/example-inc/app-operator"

func CheckGoProjectCmd added in v0.5.0

func CheckGoProjectCmd(cmd *cobra.Command) error

func ExecCmd added in v0.4.0

func ExecCmd(cmd *exec.Cmd) error

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

func GoModOn() (bool, error)

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 GoTest added in v0.8.0

func GoTest(opts GoTestOptions) error

GoTest runs "go test" configured with opts.

func IsDepManagerDep added in v0.8.0

func IsDepManagerDep() bool

func IsDepManagerGoMod added in v0.8.0

func IsDepManagerGoMod() bool

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 MustGetwd

func MustGetwd() string

func MustInProjectRoot

func MustInProjectRoot()

MustInProjectRoot checks if the current dir is the project root and returns the current repo's import path, ex github.com/example-inc/app-operator

func MustSetGopath added in v0.5.0

func MustSetGopath(currentGopath string) string

MustSetGopath sets GOPATH=currentGopath after processing a path list, if any, then returns the set path. If GOPATH cannot be set, MustSetGopath exits.

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.

Types

type DepManagerType added in v0.8.0

type DepManagerType string
const (
	DepManagerGoMod DepManagerType = "modules"
	DepManagerDep   DepManagerType = "dep"
)

func GetDepManagerType added in v0.8.0

func GetDepManagerType() (DepManagerType, error)

type ErrInvalidDepManager added in v0.8.0

type ErrInvalidDepManager string

func (ErrInvalidDepManager) Error added in v0.8.0

func (e ErrInvalidDepManager) Error() string

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
	// GoMod determines whether to set the "-mod=vendor" flag.
	// If true, "go {cmd}" will use 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 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL