util

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 20 Imported by: 13

Documentation

Overview

TODO: clean up this file

Index

Constants

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

Variables

View Source
var JsonPbMarshaler = &jsonpb.Marshaler{}

Functions

func AliasFor added in v0.22.15

func AliasFor(pkg string) string

Generate a package alias, eg 'import alias github.com/my/package' TODO: Do something prettier if this works

func ExecCmd

func ExecCmd(cmd *exec.Cmd) error

func GeneratedGoPackage

func GeneratedGoPackage(grp model.Group) string

gets the go package for the group's generated code. same as GoPackage if the types do not come from custom imports

func GetGoModule

func GetGoModule() string

the project root pkg (based on gomod location)

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 GetModuleRoot

func GetModuleRoot() string

the project root dir (based on gomod location)

func GoBuild

func GoBuild(opts GoCmdOptions) error

GoBuild runs "go build" configured with opts.

func GoCmd

func GoCmd(cmd string, opts GoCmdOptions) error

GoCmd runs "go {cmd}".

func GoModOn

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 GoModPath

func GoModPath() string

absolute path to go.mod file for current dir

func GoPackage

func GoPackage(grp model.Group) string

gets the go package for the group's types

func GoTest

func GoTest(opts GoTestOptions) error

GoTest runs "go test" configured with opts.

func KubeCodegen

func KubeCodegen(group, version, apiDir string, generators []string) error

Possible generators: (deepcopy,defaulter,client,lister,informer) or "all"

func Kubectl

func Kubectl(stdin io.Reader, args ...string) error

func KubectlApply

func KubectlApply(manifest []byte, extraArgs ...string) error

func KubectlCmd

func KubectlCmd(stdin io.Reader, args ...string) *exec.Cmd

func KubectlDelete

func KubectlDelete(manifest []byte, extraArgs ...string) error

func KubectlOut

func KubectlOut(stdin io.Reader, args ...string) (string, error)

func MarshalYaml

func MarshalYaml(m proto.Message) ([]byte, error)

func MustGetFileDir

func MustGetFileDir() string

gets the directory

func MustGetThisDir

func MustGetThisDir() string

returns absolute path to the diretory containing the .go file containing the calling function

func MustGetThisFile

func MustGetThisFile() string

returns absolute path to the .go file containing the calling function

func MustGetwd

func MustGetwd() string

func MustSetWdGopath

func MustSetWdGopath(currentGopath string) string

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 ParseGoMod

func ParseGoMod() *modfile.File

func RunMake

func RunMake(target string, opts ...func(*exec.Cmd)) error

func SetGoVerbose

func SetGoVerbose() error

SetGoVerbose sets GOFLAGS="${GOFLAGS} -v" if GOFLAGS does not already contain "-v" to make "go" command output verbose.

func UnmarshalYaml

func UnmarshalYaml(data []byte, into proto.Message) error

func WdInGoPathSrc

func WdInGoPathSrc() (bool, error)

Types

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
}

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".

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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