helper

package
v0.1.27 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: MIT Imports: 38 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileExists = errors.New("file exists")
)

Functions

func ArgsFromAny added in v0.1.4

func ArgsFromAny(in []any) []string

func BinCfssl added in v0.1.23

func BinCfssl() *bintool.BinTool

BinCfssl returns a singleton for cfssl.

func BinCfsslJSON added in v0.1.23

func BinCfsslJSON() *bintool.BinTool

BinCfsslJSON returns a singleton for cfssl.

func BinGolangCILint added in v0.1.3

func BinGolangCILint() *bintool.BinTool

BinGolangCILint returns a singleton for golangci-lint.

func BinGoreleaser added in v0.1.10

func BinGoreleaser() *bintool.BinTool

BinGoreleaser returns a singleton for goreleaser.

func BinGovulncheck added in v0.1.3

func BinGovulncheck() *bintool.BinTool

BinGovulncheck returns a singleton for govulncheck.

func BinInstall added in v0.1.24

func BinInstall(in *bintool.BinTool) error

func BinKubeControllerEnvTest added in v0.1.22

func BinKubeControllerEnvTest() *bintool.BinTool

BinKubeControllerEnvTest returns a singleton for kubeControllerEnvTest.

func BinKubeControllerGen added in v0.1.22

func BinKubeControllerGen() *bintool.BinTool

BinKubeControllerGen returns a singleton for kubeControllerGen.

func BinKustomize added in v0.1.22

func BinKustomize() *bintool.BinTool

BinKustomize returns a singleton for kustomize.

func BinProtoc added in v0.1.3

func BinProtoc() *bintool.BinTool

BinProtoc returns a singleton for protoc, also downloads the includes.

func BinProtocGenGo added in v0.1.3

func BinProtocGenGo() *bintool.BinTool

BinProtocGenGo returns a singleton for protoc-gen-go.

func BinProtocGenGoGRPC added in v0.1.3

func BinProtocGenGoGRPC() *bintool.BinTool

BinProtocGenGoGRPC returns a singleton for protoc-gen-go-grpc.

func BinProtocGenGoTwirp added in v0.1.3

func BinProtocGenGoTwirp() *bintool.BinTool

BinProtocGenGoTwirp returns a singleton for protoc-gen-twirp.

func BinVerdump added in v0.1.14

func BinVerdump() *bintool.BinTool

BinVerdump returns a singleton for verdump.

func BinWire added in v0.1.14

func BinWire() *bintool.BinTool

BinWire returns a singleton for wirebin.

func BinYQ added in v0.1.8

func BinYQ() *bintool.BinTool

BinYQ returns a singleton for yq.

func Buf added in v0.1.9

func Buf() *bintool.BinTool

func Command added in v0.1.9

func Command(cmd string) ([]byte, error)

func CommandString added in v0.1.9

func CommandString(cmd string) (string, error)

func ContextDefaultValue added in v0.1.23

func ContextDefaultValue[T any](ctx context.Context, key ContextKey, defaultValue T) T

func DownloadToCache

func DownloadToCache(src string, opts ...RestyOpt) (string, error)

func DownloadToPath added in v0.1.16

func DownloadToPath(src, dest string, opts ...RestyOpt) (string, error)

func ExtractArchive

func ExtractArchive(src, dest string, opts ...RestyOpt) error

func FileAppendLine

func FileAppendLine(filename string, fileperm os.FileMode, line string) error

func FileChanged added in v0.1.27

func FileChanged(left, right string) bool

func FileCopy added in v0.1.24

func FileCopy(src string, dst string, overwrite bool) error

func FileExists

func FileExists(path ...string) bool

FileExists returns true if any path specified exists.

func FileExistsInPath added in v0.1.14

func FileExistsInPath(glob string, path ...string) bool

func FileHash added in v0.1.27

func FileHash(filename string) (string, error)

func FileLastRune

func FileLastRune(filename string) (rune, error)

func FileLineExists

func FileLineExists(filename, targetLine string) bool

func FileNameModify

func FileNameModify(target string, fn func(string) []string) []string

func FileNameModifyReplace

func FileNameModifyReplace(from string, to ...string) func(string) []string

func FileWrite added in v0.1.22

func FileWrite(data []byte, path string) error

func FilesMatch

func FilesMatch(baseDir, pattern string) []string

func FilterCoverageOutput

func FilterCoverageOutput(filename string) error

FilterCoverageOutput filters the coverage output by removing any lines that contain generated protobuf files `.pg.go`.

func FirstCommandName added in v0.1.7

func FirstCommandName() (string, error)

func GetEnv

func GetEnv(key, fallback string) string

GetEnv returns an environment variable value if present, or a default value.

func GetFilenameForURL added in v0.1.16

func GetFilenameForURL(src string, opts ...RestyOpt) (string, error)

func GetGitTopLevel added in v0.1.16

func GetGitTopLevel(path ...string) (string, error)

func GetModuleName

func GetModuleName() (string, error)

func GetRelativePath added in v0.1.8

func GetRelativePath(path string) (string, bool)

func GitCommitTime added in v0.1.9

func GitCommitTime() time.Time

func GitHash

func GitHash() string

func GitHeadRev

func GitHeadRev() string

func GitHeadTag

func GitHeadTag() string

func GitHeadTagDescribe added in v0.1.4

func GitHeadTagDescribe() string

func GitSemver added in v0.1.4

func GitSemver() string

func GitSemverRaw added in v0.1.4

func GitSemverRaw() string

func GitSlug

func GitSlug() string

func GitURL added in v0.1.4

func GitURL() string

func GoEnv added in v0.1.19

func GoEnv(key, fallback string) string

func GolangVersion added in v0.1.5

func GolangVersion() string

func GolangVersionRaw added in v0.1.5

func GolangVersionRaw() string

func HTTPGetLatestGitHubReleaseMatchingTag added in v0.1.10

func HTTPGetLatestGitHubReleaseMatchingTag(slug string, r *regexp.Regexp, opts ...RestyOpt) (string, error)

func HTTPGetLatestGitHubVersion

func HTTPGetLatestGitHubVersion(slug string, opts ...RestyOpt) (string, error)

func HTTPWriteFile

func HTTPWriteFile(rawURL, filename string, eTag *ETagItem, fileperm os.FileMode, opts ...RestyOpt) error

func IfErrorf added in v0.1.9

func IfErrorf(format string, a ...any) error

func IfErrorfWrap added in v0.1.9

func IfErrorfWrap[T any](format string) func(T, error) (T, error)

func KubernetesGetCurrentContext added in v0.1.7

func KubernetesGetCurrentContext() (string, error)

func KubernetesGetPodWithSelector added in v0.1.7

func KubernetesGetPodWithSelector(selector string) (string, error)

func LDFlags

func LDFlags(debug bool) []string

LDFlags returns the ldflags argument for `go build`.

func MergeYaml added in v0.1.8

func MergeYaml(leftFile, rightFile string) ([]byte, error)

func Must added in v0.1.7

func Must[T any](in T, err error) T

Must takes a function that returns T, error and if the error is not nil panics, otherwise returns just T.

func MustCommandPaths

func MustCommandPaths() []string

func MustGetArtifactPath added in v0.1.7

func MustGetArtifactPath(path ...string) string

MustGetArtifactPath get artifact directory or panic if unable to.

func MustGetGitTopLevel added in v0.1.16

func MustGetGitTopLevel(path ...string) string

func MustGetGoBin

func MustGetGoBin(path ...string) string

MustGetGoBin get GOBIN.

if GOBIN is not set then attempt to derive its value using GOPATH.

if GOPATH is not set, use (pwd)/artifacts/bin .

func MustGetHomeDir

func MustGetHomeDir(path ...string) string

MustGetHomeDir get user home directory or panic if unable to.

func MustGetProtobufPath

func MustGetProtobufPath() string

func MustGetVSCodePath added in v0.1.4

func MustGetVSCodePath(path ...string) string

MustGetVSCodePath get generated .vscode directory.

if the directory does not exist then it will be created.

if the directory cannot be created then panic.

func MustGetWD

func MustGetWD(path ...string) string

MustGetWD get working directory or panic if unable to.

func MustMakeDir

func MustMakeDir(path string, fileperm os.FileMode)

MustMakeDir make directory, including parents if required.

if unable to make directory then panic.

func PanicIfError

func PanicIfError(err error, prependStr string)

PanicIfError panics if passed error is not nil.

prependStr is optional string to prepend to panic error.

func PrintDebug

func PrintDebug(format string, v ...any)

PrintDebug prints the passed debug message to stdout in white text with blue chevron.

func PrintFileUpdate added in v0.1.27

func PrintFileUpdate(format string, v ...any)

PrintFileUpdate prints the passed message to stdout in white text with magenta chevron.

func PrintInfo

func PrintInfo(format string, v ...any)

PrintInfo prints the passed info message to stdout in white text with green chevron.

func PrintWarning

func PrintWarning(format string, v ...any)

PrintWarn prints the passed warning message to stdout in white text with yellow chevron.

func ProtobufIncludePaths

func ProtobufIncludePaths() []string

ProtobufIncludePaths returns the `--proto_path` arguments for the protocol buffer gen command.

func RestyTrace added in v0.1.16

func RestyTrace(resp *resty.Response, err error)

func SanitizeArchivePath

func SanitizeArchivePath(dest, target string) (string, error)

Sanitize archive file pathing from "G305: Zip Slip vulnerability".

func SemverBumpPatch added in v0.1.4

func SemverBumpPatch(v string) string

func SetEnv

func SetEnv(key, value string) func()

func TargetNeedRefresh

func TargetNeedRefresh(target string, src ...string) bool

func Uncompress added in v0.1.16

func Uncompress(src, dest string) error

func Untargz added in v0.1.16

func Untargz(src, dest string) error

func Unzip

func Unzip(src, dest string) error

Types

type BuildPlatform added in v0.1.4

type BuildPlatform struct {
	OS   string
	Arch string
}

type CommandEnv

type CommandEnv struct {
	// contains filtered or unexported fields
}

func (*CommandEnv) Revert

func (e *CommandEnv) Revert()

type CommandTemplate

type CommandTemplate struct {
	Debug bool

	CGO       string
	GoOS      string
	GoArch    string
	GoArm     string
	GoVersion string

	GitRev     string
	GitHash    string
	GitHeadTag string
	GitSlug    string

	LDFlags string

	CWD string

	OutputArtifact string
	TargetPath     string
	CommandDir     string
	CommandName    string
	HomeDir        string
}

func NewCommandTemplate

func NewCommandTemplate(debug bool, commandDir string) *CommandTemplate

func (*CommandTemplate) Render

func (t *CommandTemplate) Render(cmd string) (string, error)

type ContextKey added in v0.1.23

type ContextKey string
const (
	DockerLocalPlatform ContextKey = "docker-local-platform"
)

type DockerConfig added in v0.1.4

type DockerConfig struct {
	Image       string                 `yaml:"image,omitempty"`
	Platforms   []string               `yaml:"platforms,omitempty"`
	Tag         interface{}            `yaml:"tag,omitempty"`
	BlockedTags []string               `yaml:"blocked_tags,omitempty"`
	BuildArgs   map[string]string      `yaml:"build_args,omitempty"`
	Kubernetes  DockerConfigKubernetes `yaml:"kubernetes,omitempty"`
	Mirrord     DockerConfigMirrord    `yaml:"mirrord,omitempty"`
	Ignore      []string               `yaml:"ignore,omitempty"`
}

func DockerLoadConfig added in v0.1.4

func DockerLoadConfig() (*DockerConfig, error)

func (DockerConfig) Args added in v0.1.4

func (d DockerConfig) Args(ctx context.Context) []string

func (DockerConfig) ArgsTag added in v0.1.4

func (d DockerConfig) ArgsTag(tag string) (string, error)

func (DockerConfig) GetImage added in v0.1.5

func (d DockerConfig) GetImage() string

func (DockerConfig) GetImageRef added in v0.1.22

func (d DockerConfig) GetImageRef() string

func (DockerConfig) GetTags added in v0.1.4

func (d DockerConfig) GetTags() []string

func (DockerConfig) IsBlocked added in v0.1.4

func (d DockerConfig) IsBlocked(in string) bool

func (DockerConfig) OSArch added in v0.1.4

func (d DockerConfig) OSArch() []BuildPlatform

type DockerConfigKubernetes added in v0.1.7

type DockerConfigKubernetes struct {
	Deployment  string `yaml:"deployment,omitempty"`
	PodSelector string `yaml:"pod-selector,omitempty"`
}

type DockerConfigMirrord added in v0.1.9

type DockerConfigMirrord struct {
	Targetless bool `yaml:"targetless,omitempty"`
}

type ETag added in v0.1.8

type ETag []ETagItem

func ETagLoadConfig added in v0.1.8

func ETagLoadConfig() (ETag, error)

func (ETag) Get added in v0.1.8

func (e ETag) Get(key string) string

func (ETag) GetItem added in v0.1.8

func (e ETag) GetItem(key string) *ETagItem

func (ETag) GetRelative added in v0.1.8

func (e ETag) GetRelative(path string) string

func (ETag) Save added in v0.1.8

func (e ETag) Save() error

func (*ETag) Set added in v0.1.8

func (e *ETag) Set(key, value string)

type ETagItem added in v0.1.8

type ETagItem struct {
	Key   string `yaml:"name"`
	Value string `yaml:"value"`
	// contains filtered or unexported fields
}

func (*ETagItem) Save added in v0.1.8

func (e *ETagItem) Save() error

type Module

type Module struct {
	Path       string       `json:"Path"`       // module path
	Query      string       `json:"Query"`      // version query corresponding to this version
	Version    string       `json:"Version"`    // module version
	Versions   []string     `json:"Versions"`   // available module versions
	Replace    *Module      `json:"Replace"`    // replaced by this module
	Time       *time.Time   `json:"Time"`       // time version was created
	Update     *Module      `json:"Update"`     // available update (with -u)
	Main       bool         `json:"Main"`       // is this the main module?
	Indirect   bool         `json:"Indirect"`   // module is only indirectly needed by main module
	Dir        string       `json:"Dir"`        // directory holding local copy of files, if any
	GoMod      string       `json:"GoMod"`      // path to go.mod file describing module, if any
	GoVersion  string       `json:"GoVersion"`  // go version used in module
	Retracted  []string     `json:"Retracted"`  // retraction information, if any (with -retracted or -u)
	Deprecated string       `json:"Deprecated"` // deprecation message, if any (with -u)
	Error      *ModuleError `json:"Error"`      // error loading module
	Origin     any          `json:"Origin"`     // provenance of module
	Reuse      bool         `json:"Reuse"`      // reuse of old module info is safe
}

Module is a module returned by `go list`.

func GolangListModules

func GolangListModules() ([]Module, error)

GolangListModules executes `go list -m all` and returned the parsed Module slice.

type ModuleError

type ModuleError struct {
	Err string `json:"Err"` // the error itself
}

ModuleError is the possible error when loading a module.

type ProtobufTargetFunc added in v0.1.2

type ProtobufTargetFunc func() []string

ProtobufTargetFunc returned by ProtobufTargets, each ProtobufTargetFunc returns a list of `*.proto` files in each directory.

func ProtobufTargets

func ProtobufTargets() []ProtobufTargetFunc

ProtobufTargets returns a slice of functions that return a list of files in a specific directory

example: root |-blah1 [test1.proto, test2.proto] \-blah2 [testa.proto, testb.proto]

returns two functions, one that returns [/root/blah1/test1.proto, /root/blah1/test2.proto] and another that returns [/root/blah2/testa.proto /root/blah2/testb.proto].

type RestyOpt added in v0.1.16

type RestyOpt func(*resty.Client)

func AddAuthToken added in v0.1.16

func AddAuthToken(token string) RestyOpt

func AddHeader added in v0.1.16

func AddHeader(key, value string) RestyOpt

type VersionCache added in v0.1.7

type VersionCache map[VersionKey]string

func MustVersionLoadCache added in v0.1.7

func MustVersionLoadCache() *VersionCache

func VersionLoadCache added in v0.1.7

func VersionLoadCache() (*VersionCache, error)

func (VersionCache) GetVersion added in v0.1.7

func (vc VersionCache) GetVersion(key VersionKey) string

func (VersionCache) Save added in v0.1.7

func (vc VersionCache) Save() error

func (VersionCache) SetVersion added in v0.1.7

func (vc VersionCache) SetVersion(key VersionKey, value string) string

type VersionKey added in v0.1.7

type VersionKey string
const (
	GolangciLintVersion          VersionKey = "golangci-lint"
	GovulncheckVersion           VersionKey = "govulncheck"
	ProtocVersion                VersionKey = "protoc"
	ProtocGenGoVersion           VersionKey = "protoc-gen-go"
	ProtocGenGoGRPCVersion       VersionKey = "protoc-gen-go-grpc"
	ProtocGenGoTwirpVersion      VersionKey = "protoc-gen-go-twirp"
	YQVersion                    VersionKey = "yq"
	BufVersion                   VersionKey = "buf"
	GoreleaserVersion            VersionKey = "goreleaser"
	WireVersion                  VersionKey = "wire"
	VerdumpVersion               VersionKey = "verdump"
	KubeControllerGenVersion     VersionKey = "v0.14.0"
	KustomizeVersion             VersionKey = "v5.3.0"
	KubeControllerEnvTestVersion VersionKey = "latest"
	CFSSLVersion                 VersionKey = "cfssl"
)

func (VersionKey) Key added in v0.1.7

func (vk VersionKey) Key() string

func (VersionKey) String added in v0.1.7

func (vk VersionKey) String() string

Jump to

Keyboard shortcuts

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