util

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: Apache-2.0 Imports: 29 Imported by: 41

Documentation

Index

Constants

View Source
const GsutilExec = "gsutil"
View Source
const Loopback = "127.0.0.1"

Loopback network address. Skaffold should not bind to 0.0.0.0 unless we really want to expose something to the network.

Variables

View Source
var (
	OSEnviron = os.Environ
)

For testing

View Source
var SkipWrapperCheck = false

Functions

func AbsFile added in v0.16.0

func AbsFile(workspace string, filename string) (string, error)

AbsFile resolves the absolute path of the file named filename in directory workspace, erroring if it is not a file

func AbsolutePaths added in v0.24.0

func AbsolutePaths(workspace string, paths []string) []string

AbsolutePaths prepends each path in paths with workspace if the path isn't absolute

func BoolPtr

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to a bool

func CloneThroughJSON added in v0.23.0

func CloneThroughJSON(old interface{}, new interface{})

CloneThroughJSON clones an `old` object into a `new` one using json marshalling and unmarshalling. Since the object can be marshalled, it's almost sure it can be unmarshalled. So we prefer to panic instead of returning an error that would create an untestable branch on the call site.

func CloneThroughYAML added in v0.31.0

func CloneThroughYAML(old interface{}, new interface{})

CloneThroughYAML clones an `old` object into a `new` one using yaml marshalling and unmarshalling. Since the object can be marshalled, it's almost sure it can be unmarshalled. So we prefer to panic instead of returning an error that would create an untestable branch on the call site.

func CreateMappedTar added in v0.23.0

func CreateMappedTar(w io.Writer, root string, pathMap map[string][]string) error

func CreateTar added in v0.4.0

func CreateTar(w io.Writer, root string, paths []string) error

func CreateTarGz

func CreateTarGz(w io.Writer, root string, paths []string) error

func CreateTarWithParents added in v1.1.0

func CreateTarWithParents(w io.Writer, root string, paths []string, uid, gid int, modTime time.Time) error

func Download added in v0.21.0

func Download(url string) ([]byte, error)

func EnvMapToSlice added in v1.7.1

func EnvMapToSlice(m map[string]string, separator string) []string

EnvMapToSlice converts map of (string,string) to string slice

func EnvPtrMapToSlice added in v1.7.1

func EnvPtrMapToSlice(m map[string]*string, separator string) []string

EnvPtrMapToSlice converts map of (string,*string) to string slice

func EnvSliceToMap added in v1.7.1

func EnvSliceToMap(slice []string, separator string) map[string]string

EnvSliceToMap converts a string slice into a map of (string,string) using the given separator

func EvaluateEnvTemplateMap added in v1.7.1

func EvaluateEnvTemplateMap(args map[string]*string) (map[string]*string, error)

EvaluateEnvTemplateMap parses and executes all map values as templates based on OS environment variables

func EvaluateEnvTemplateMapWithEnv added in v1.7.1

func EvaluateEnvTemplateMapWithEnv(args map[string]*string, env map[string]string) (map[string]*string, error)

EvaluateEnvTemplateMapWithEnv parses and executes all map values as templates based on OS and custom environment variables

func ExecuteEnvTemplate added in v0.7.0

func ExecuteEnvTemplate(envTemplate *template.Template, customMap map[string]string) (string, error)

ExecuteEnvTemplate executes an envTemplate based on OS environment variables and a custom map

func Expand added in v0.15.0

func Expand(text, key, value string) string

Expand replaces placeholders for a given key with a given value. It supports the ${key} and the $key syntax.

func ExpandEnvTemplate added in v1.5.0

func ExpandEnvTemplate(s string, envMap map[string]string) (string, error)

ExpandEnvTemplate parses and executes template s with an optional environment map

func ExpandEnvTemplateOrFail added in v1.18.0

func ExpandEnvTemplateOrFail(s string, envMap map[string]string) (string, error)

ExpandEnvTemplateOrFail parses and executes template s with an optional environment map, and errors if a reference cannot be satisfied.

func ExpandPathsGlob

func ExpandPathsGlob(workingDir string, paths []string) ([]string, error)

ExpandPathsGlob expands paths according to filepath.Glob patterns Returns a list of unique files that match the glob patterns passed in.

func IsDir added in v0.38.0

func IsDir(path string) bool

func IsFile added in v0.38.0

func IsFile(path string) bool

func IsHiddenDir added in v0.25.0

func IsHiddenDir(filename string) bool

IsHiddenDir returns if a directory is hidden.

func IsHiddenFile added in v0.25.0

func IsHiddenFile(filename string) bool

IsHiddenFile returns if a file is hidden. File is hidden if it starts with prefix "."

func IsPortFree added in v0.35.0

func IsPortFree(address string, p int) bool

func IsSubPath added in v1.7.1

func IsSubPath(basepath string, targetpath string) bool

IsSubPath return true if targetpath is sub-path of basepath; doesn't check for symlinks

func IsTerminal added in v1.3.0

func IsTerminal(w io.Writer) (uintptr, bool)

func IsURL added in v0.21.0

func IsURL(s string) bool

func MapToFlag added in v1.7.1

func MapToFlag(m map[string]*string, flag string) ([]string, error)

MapToFlag parses all map values and returns them as `key=value` with the given flag Example: --my-flag key0=value0 --my-flag key1=value1 --my-flag key2=value2

func NonEmptyLines added in v0.17.0

func NonEmptyLines(input []byte) []string

NonEmptyLines scans the provided input and returns the non-empty strings found as an array

func ParseEnvTemplate added in v0.7.0

func ParseEnvTemplate(t string) (*template.Template, error)

ParseEnvTemplate is a simple wrapper to parse an env template

func RandomID

func RandomID() string

func ReadConfiguration added in v0.4.0

func ReadConfiguration(filename string) ([]byte, error)

ReadConfiguration reads a `skaffold.yaml` configuration and returns its content.

func RealWorkDir added in v1.18.0

func RealWorkDir() (string, error)

On macOS, $PWD can have a different case that the actual current working directory. That happens for example if one does: `cd /home/me/MY-PROJECT` before running Skaffold, instead of `cd /home/me/my-project`. In such a situation, the file watcher will fail to detect changes. To solve that, we force `os.Getwd()` not to use $PWD. See: https://github.com/rjeczalik/notify/issues/96

func RegexEqual added in v1.7.1

func RegexEqual(expected, actual string) bool

RegexEqual matches the string 'actual' against a regex compiled from 'expected' If 'expected' is not a valid regex, string comparison is used as fallback

func RemoveFromSlice added in v0.14.0

func RemoveFromSlice(s []string, target string) []string

RemoveFromSlice removes a string from a slice of strings

func RunCmd added in v0.6.0

func RunCmd(cmd *exec.Cmd) error

func RunCmdOut added in v0.6.0

func RunCmdOut(cmd *exec.Cmd) ([]byte, error)

func ShowHumanizeTime added in v1.18.0

func ShowHumanizeTime(start time.Duration) string

ShowHumanizeTime returns time in human readable format

func StrSliceContains

func StrSliceContains(sl []string, s string) bool

func StrSliceIndex added in v0.30.0

func StrSliceIndex(sl []string, s string) int

func StrSliceInsert added in v0.32.0

func StrSliceInsert(sl []string, index int, insert []string) []string

func StringPtr added in v0.11.0

func StringPtr(s string) *string

StringPtr returns a pointer to a string

func VerifyOrCreateFile added in v0.13.0

func VerifyOrCreateFile(path string) error

VerifyOrCreateFile checks if a file exists at the given path, and if not, creates all parent directories and creates the file.

Types

type Command

type Command interface {
	RunCmdOut(cmd *exec.Cmd) ([]byte, error)
	RunCmd(cmd *exec.Cmd) error
}

Command is an interface used to run commands. All packages should use this interface instead of calling exec.Cmd directly.

var DefaultExecCommand Command = &Commander{}

DefaultExecCommand runs commands using exec.Cmd

type CommandWrapper added in v0.16.0

type CommandWrapper struct {
	// Executable is the base name of the command, like `gradle`
	Executable string

	// Wrapper is the optional base name of a command wrapper, like `gradlew`
	Wrapper string
}

CommandWrapper defines an association between an executable command (like `gradle`) and possible command wrappers (like `gradlew`). `CreateCommand` uses this definition to create a `Cmd` object. Maven and Gradle projects often provide a wrapper script to ensure a particular version of their builder is used.

func (CommandWrapper) CreateCommand added in v0.16.0

func (cw CommandWrapper) CreateCommand(ctx context.Context, workingDir string, args []string) exec.Cmd

CreateCommand creates an `exec.Cmd` that is configured to call the executable (possibly using a wrapper in `workingDir`, when found) with the given arguments, with working directory set to `workingDir`.

type Commander

type Commander struct{}

Commander is the exec.Cmd implementation of the Command interface

func (*Commander) RunCmd added in v0.6.0

func (*Commander) RunCmd(cmd *exec.Cmd) error

RunCmd runs an exec.Command.

func (*Commander) RunCmdOut added in v0.6.0

func (*Commander) RunCmdOut(cmd *exec.Cmd) ([]byte, error)

RunCmdOut runs an exec.Command and returns the stdout and error.

type Gsutil added in v1.7.1

type Gsutil struct{}

func (*Gsutil) Copy added in v1.7.1

func (g *Gsutil) Copy(ctx context.Context, src, dst string, recursive bool) error

Copy calls `gsutil cp [-r] <source_url> <destination_url>

type PortSet added in v1.7.1

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

func (*PortSet) Delete added in v1.7.1

func (f *PortSet) Delete(port int)

func (*PortSet) Length added in v1.7.1

func (f *PortSet) Length() int

func (*PortSet) List added in v1.7.1

func (f *PortSet) List() []int

func (*PortSet) LoadOrSet added in v1.7.1

func (f *PortSet) LoadOrSet(port int) bool

func (*PortSet) Set added in v1.7.1

func (f *PortSet) Set(port int)

type StoreError added in v1.7.1

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

StoreError represent any error that when retrieving errors from the store.

func (StoreError) Error added in v1.7.1

func (e StoreError) Error() string

type StringSet added in v1.18.0

type StringSet map[string]unit

StringSet helps to de-duplicate a set of strings.

func NewStringSet added in v1.18.0

func NewStringSet() StringSet

NewStringSet returns a new StringSet object.

func (StringSet) Contains added in v1.18.0

func (s StringSet) Contains(str string) bool

func (StringSet) Insert added in v1.18.0

func (s StringSet) Insert(strings ...string)

Insert adds strings to the set.

func (StringSet) ToList added in v1.18.0

func (s StringSet) ToList() []string

ToList returns the sorted list of inserted strings.

type SyncStore added in v1.7.1

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

SyncStore exports a single method `Exec` to ensure single execution of a function and share the result between all callers of the function.

func NewSyncStore added in v1.7.1

func NewSyncStore() *SyncStore

NewSyncStore returns a new instance of `SyncStore`

func (*SyncStore) Exec added in v1.7.1

func (o *SyncStore) Exec(key string, f func() interface{}) interface{}

Exec executes the function f if and only if it's being called the first time for a specific key. If it's called multiple times for the same key only the first call will execute and store the result of f. All other calls will be blocked until the running instance of f returns and all of them receive the same result.

func (*SyncStore) Store added in v1.17.2

func (o *SyncStore) Store(key string, r interface{})

Store will store the results for a key in a cache This function is not safe to use if multiple subroutines store the result for the same key.

Jump to

Keyboard shortcuts

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