util

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddNewStringsToStringArray

func AddNewStringsToStringArray(list []string, elmsToAdd ...string) []string

func BufferedPipedWriterProcess

func BufferedPipedWriterProcess(f func(w io.WriteCloser)) io.ReadCloser

func Chown

func Chown(path string, uid, gid *uint32) error

func CopyArr

func CopyArr[T any](arr []T) (ret []T)

func CopyFileIntoTar

func CopyFileIntoTar(tw *tar.Writer, tarEntryName, filePath string) error

func CopyGitIndexEntryIntoTar

func CopyGitIndexEntryIntoTar(tw *tar.Writer, tarEntryName string, entry *index.Entry, obj plumbing.EncodedObject) error

func CopyMap

func CopyMap[K comparable, V any](m map[K]V) (ret map[K]V)

func CopyTar

func CopyTar(ctx context.Context, in io.Reader, tw *tar.Writer, opts CopyTarOptions) error

func CreateArchive

func CreateArchive(archivePath string, f func(tw *tar.Writer) error) error

func CreateArchiveBasedOnAnotherOne

func CreateArchiveBasedOnAnotherOne(ctx context.Context, sourceArchivePath, destinationArchivePath string, opts CreateArchiveOptions) error

func DirExists

func DirExists(path string) (bool, error)

func DumpYaml

func DumpYaml(v interface{}) string

func ExcludeFromStringArray

func ExcludeFromStringArray(list []string, elmsToRemove ...string) []string

func ExecKubectlCmd

func ExecKubectlCmd(args ...string) *exec.Cmd

func ExecWerfBinaryCmd

func ExecWerfBinaryCmd(args ...string) *exec.Cmd

func ExpandPath

func ExpandPath(path string) string

func ExtractTar

func ExtractTar(tarFileReader io.Reader, dstDir string, opts ExtractTarOptions) error

func FileExists

func FileExists(path string) (bool, error)

FileExists returns true if path exists

func FilepathsWithParents

func FilepathsWithParents(path string) []string

func FilterSlice

func FilterSlice[V any](slice []V, filterFunc func(i int, val V) bool) []V

func FindDuplicatedStrings

func FindDuplicatedStrings(elems []string) []string

func FirstMatchInSliceIndex

func FirstMatchInSliceIndex[V any](slice []V, matchFunc func(i int, val V) bool) *int

Returns nil if no match.

func GenerateConsistentRandomString

func GenerateConsistentRandomString(n int) string

func GetAbsoluteFilepath

func GetAbsoluteFilepath(absOrRelPath string) string

func GetBoolEnvironment

func GetBoolEnvironment(environmentName string) *bool

func GetBoolEnvironmentDefaultFalse

func GetBoolEnvironmentDefaultFalse(environmentName string) bool

func GetBoolEnvironmentDefaultTrue

func GetBoolEnvironmentDefaultTrue(environmentName string) bool

func GetFirstExistingEnvVarAsString

func GetFirstExistingEnvVarAsString(envNames ...string) string

func GetInt64EnvVar

func GetInt64EnvVar(varName string) (*int64, error)

func GetIntEnvVar

func GetIntEnvVar(varName string) (*int64, error)

func GetRelativeToBaseFilepath

func GetRelativeToBaseFilepath(base, path string) string

func GetUint64EnvVar

func GetUint64EnvVar(varName string) (*uint64, error)

func GlobPrefixWithoutPatterns

func GlobPrefixWithoutPatterns(glob string) (string, string)

GlobPrefixWithoutPatterns figures out how many components we don't need to glob because they're just names without patterns

func HashContentsAndPathsRecurse

func HashContentsAndPathsRecurse(path string) (string, error)

For file: hash contents of file with its name. For directory: hash contents of all files in directory, along with their relative filenames.

func InterfaceArrayToStringArray

func InterfaceArrayToStringArray(array []interface{}) ([]string, error)

func InterfaceToMapStringInterface

func InterfaceToMapStringInterface(value interface{}) (map[string]interface{}, error)

func InterfaceToStringArray

func InterfaceToStringArray(value interface{}) ([]string, error)

func IsInContainer

func IsInContainer() bool

func IsNotADirectoryError

func IsNotADirectoryError(err error) bool

func IsStringsContainValue

func IsStringsContainValue(arr []string, value string) bool

func IsSubpathOfBasePath

func IsSubpathOfBasePath(basePath, path string) bool

func LegacyMurmurHash

func LegacyMurmurHash(args ...string) string

LegacyMurmurHash function returns a hash of non-fixed length (1-8 symbols)

func LookupBoolEnvironment

func LookupBoolEnvironment(environmentName string) (*bool, bool)

func MapFuncToSlice

func MapFuncToSlice[T, RT any, FT func(T) RT](arr []T, f FT) (res []RT)

func MapKeys

func MapKeys[M ~map[K]V, K comparable, V any](m M) (res []K)

func MapLoadOrCreateMutex

func MapLoadOrCreateMutex(m *sync.Map, key string) *sync.Mutex

func MapMustLoad

func MapMustLoad(m *sync.Map, key string) interface{}

func MapStringInterfaceToMapStringString

func MapStringInterfaceToMapStringString(value map[string]interface{}) map[string]string

func MapValues

func MapValues[M ~map[K]V, K comparable, V any](m M) (res []V)

func MergeMaps

func MergeMaps[K comparable, V any](src, dest map[K]V) map[K]V

Dest has higher priority.

func NumerateLines

func NumerateLines(text string, firstLineNumber int) string

func PredefinedValuesByEnvNamePrefix

func PredefinedValuesByEnvNamePrefix(envNamePrefix string, envNamePrefixesToExcept ...string) []string

func RegularFileExists

func RegularFileExists(path string) (bool, error)

func RejectEmptyStrings

func RejectEmptyStrings(arr []string) []string

func Reverse

func Reverse(s string) string

func SafeTrimGlobsAndSlashesFromFilepath

func SafeTrimGlobsAndSlashesFromFilepath(p string) string

SafeTrimGlobsAndSlashesFromFilepath trims any trailing globs and/or slashes from the path, while ignoring globs that are part of a directory or file name.

func SafeTrimGlobsAndSlashesFromPath

func SafeTrimGlobsAndSlashesFromPath(p string) string

func Sha256Hash

func Sha256Hash(args ...string) string

func Sha3_224Hash

func Sha3_224Hash(args ...string) string

func SortedStringKeys

func SortedStringKeys[T map[string]any](m T) []string

func SplitFilepath

func SplitFilepath(path string) (result []string)

func SplitLines

func SplitLines(s string) []string

func ToLinuxContainerPath

func ToLinuxContainerPath(path string) string

func UniqAppendString

func UniqAppendString(arr []string, value string) []string

func UniqStrings

func UniqStrings(arr []string) []string

func WriteDirAsTar

func WriteDirAsTar(dir string, w io.Writer) error

Types

type CopyTarOptions

type CopyTarOptions struct {
	IncludePaths []string
	ExcludePaths []string
}

type CreateArchiveOptions

type CreateArchiveOptions struct {
	CopyTarOptions
	AfterCopyFunc func(tw *tar.Writer) error
}

type ExtractTarOptions

type ExtractTarOptions struct {
	UID, GID *uint32
}

type GoroutineSafeBuffer

type GoroutineSafeBuffer struct {
	*bytes.Buffer
	// contains filtered or unexported fields
}

func (*GoroutineSafeBuffer) Bytes

func (b *GoroutineSafeBuffer) Bytes() []byte

func (*GoroutineSafeBuffer) Cap

func (b *GoroutineSafeBuffer) Cap() int

func (*GoroutineSafeBuffer) Grow

func (b *GoroutineSafeBuffer) Grow(n int)

func (*GoroutineSafeBuffer) Len

func (b *GoroutineSafeBuffer) Len() int

func (*GoroutineSafeBuffer) Next

func (b *GoroutineSafeBuffer) Next(n int) []byte

func (*GoroutineSafeBuffer) Read

func (b *GoroutineSafeBuffer) Read(p []byte) (n int, err error)

func (*GoroutineSafeBuffer) ReadByte

func (b *GoroutineSafeBuffer) ReadByte() (c byte, err error)

func (*GoroutineSafeBuffer) ReadBytes

func (b *GoroutineSafeBuffer) ReadBytes(delim byte) (line []byte, err error)

func (*GoroutineSafeBuffer) ReadFrom

func (b *GoroutineSafeBuffer) ReadFrom(r io.Reader) (n int64, err error)

func (*GoroutineSafeBuffer) ReadRune

func (b *GoroutineSafeBuffer) ReadRune() (r rune, size int, err error)

func (*GoroutineSafeBuffer) ReadString

func (b *GoroutineSafeBuffer) ReadString(delim byte) (line string, err error)

func (*GoroutineSafeBuffer) Reset

func (b *GoroutineSafeBuffer) Reset()

func (*GoroutineSafeBuffer) String

func (b *GoroutineSafeBuffer) String() string

func (*GoroutineSafeBuffer) Truncate

func (b *GoroutineSafeBuffer) Truncate(n int)

func (*GoroutineSafeBuffer) UnreadByte

func (b *GoroutineSafeBuffer) UnreadByte() error

func (*GoroutineSafeBuffer) UnreadRune

func (b *GoroutineSafeBuffer) UnreadRune() error

func (*GoroutineSafeBuffer) Write

func (b *GoroutineSafeBuffer) Write(p []byte) (n int, err error)

func (*GoroutineSafeBuffer) WriteByte

func (b *GoroutineSafeBuffer) WriteByte(c byte) error

func (*GoroutineSafeBuffer) WriteRune

func (b *GoroutineSafeBuffer) WriteRune(r rune) (n int, err error)

func (*GoroutineSafeBuffer) WriteString

func (b *GoroutineSafeBuffer) WriteString(s string) (n int, err error)

func (*GoroutineSafeBuffer) WriteTo

func (b *GoroutineSafeBuffer) WriteTo(w io.Writer) (n int64, err error)

type Pair

type Pair[T1, T2 any] struct {
	First  T1
	Second T2
}

func NewPair

func NewPair[T1, T2 any](first T1, second T2) Pair[T1, T2]

func (Pair[T1, T2]) String

func (p Pair[T1, T2]) String() string

func (Pair[T1, T2]) Unpair

func (p Pair[T1, T2]) Unpair() (T1, T2)

type SerializableError

type SerializableError struct {
	Error error
}

func (SerializableError) MarshalJSON

func (obj SerializableError) MarshalJSON() ([]byte, error)

func (*SerializableError) UnmarshalJSON

func (obj *SerializableError) UnmarshalJSON(data []byte) error

type Stack

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

func NewStack

func NewStack() *Stack

Create a new stack

func (*Stack) Len

func (this *Stack) Len() int

Return the number of items in the stack

func (*Stack) Peek

func (this *Stack) Peek() interface{}

View the top item on the stack

func (*Stack) Pop

func (this *Stack) Pop() interface{}

Pop the top item of the stack and return it

func (*Stack) Push

func (this *Stack) Push(value interface{})

Push a value onto the top of the stack

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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