utils

package
v0.0.0-...-333d07d Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultNumber

func DefaultNumber[T Number](values ...T) T

func DefaultStr

func DefaultStr(values ...string) string

DefaultStr returns the first non-empty string

func EquivalentVersion

func EquivalentVersion(a string, b string) bool

func GetOrDefault

func GetOrDefault(str string, defaultStr string) string

func GetVersionTag

func GetVersionTag(imageDescriptor string) string

func IntSliceContains

func IntSliceContains(s []int, e int) bool

func IsDirEmpty

func IsDirEmpty(name string) (bool, error)

func IsValidFor

func IsValidFor(actual string, minimum string) bool

func LabelToMap

func LabelToMap(label string) map[string]string

LabelToMap expects label string to be a comma separated list of key and value pairs delimited by equals.

func LessRecentThanVersion

func LessRecentThanVersion(a string, b string) bool

func MoreRecentThanVersion

func MoreRecentThanVersion(a string, b string) bool

func PrettyPrintCommand

func PrettyPrintCommand(command string, args []string) string

func RandomId

func RandomId(length int) string

func ReadUsername

func ReadUsername() string

func RegexpStringSliceContains

func RegexpStringSliceContains(s []string, e string) bool

func Retry

func Retry(interval time.Duration, maxRetries int, f ConditionFunc) error

Retry retries f every interval until after maxRetries.

The interval won't be affected by how long f takes. For example, if interval is 3s, f takes 1s, another f will be called 2s later. However, if f takes longer than interval, it will be delayed.

If an error is received from f, fail immediately and return that error (no further retries).

Keep in mind that the second argument is for max _retries_. So, with a value of 1, f() will run at most 2 times (one try and one _retry_).

func RetryError

func RetryError(interval time.Duration, maxRetries int, f CheckedFunc) error

This is similar to Retry(), but it will not fail immediately on errors, and if the retries are exhausted and f() still failing, it will return f()'s error

func RetryErrorWithContext

func RetryErrorWithContext(ctx context.Context, interval time.Duration, f CheckedFunc) error

RetryErrorWithContext will retry as long the checked function is returning an error and the context does not time out

func RetryWithContext

func RetryWithContext(ctx context.Context, interval time.Duration, f ConditionFunc) error

RetryWithContext retries f every interval until the specified context times out.

func StringSliceContains

func StringSliceContains(s []string, e string) bool

func StringSliceEndsWith

func StringSliceEndsWith(s []string, e string) bool

func StringSlicesEqual

func StringSlicesEqual(a, b []string) bool

func StringifySelector

func StringifySelector(labels map[string]string) string

func TcpPortInUse

func TcpPortInUse(host string, port int) bool

func TcpPortNextFree

func TcpPortNextFree(startPort int) (int, error)

func TryUntil

func TryUntil(maxWindowTime time.Duration, f ResultFunc) (interface{}, error)

Types

type CheckedFunc

type CheckedFunc func() error

type ConditionFunc

type ConditionFunc func() (bool, error)

type DirectoryReader

type DirectoryReader struct{}

func (*DirectoryReader) ReadDir

func (f *DirectoryReader) ReadDir(dirname string, filter FilenameFilter) ([]string, error)

type FilenameFilter

type FilenameFilter func(string) bool

type Number

type Number interface {
	int | int32 | int64 | float32 | float64
}

type Result

type Result struct {
	Value interface{}
	Error error
}

type ResultFunc

type ResultFunc func() Result

type Tarball

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

func NewTarball

func NewTarball() *Tarball

NewTarball returns an initialized Tarball

func (*Tarball) AddFileData

func (t *Tarball) AddFileData(fileName string, mode int64, mod time.Time, data []byte) error

func (*Tarball) AddFiles

func (t *Tarball) AddFiles(dir string, includesOnly ...string) error

AddFiles adds all files (recursively) based on the provided directory.

func (*Tarball) Extract

func (t *Tarball) Extract(fileName, outputPath string) error

Extract extracts the given tar.gz filename into the provided outputPath

func (*Tarball) ExtractData

func (t *Tarball) ExtractData(data []byte, outputPath string) error

func (*Tarball) Save

func (t *Tarball) Save(filename string) error

Save saves tarball based on added directories. The provided filename will be created or truncated if it already exists. Once Save method is executed, this instance cannot be used anymore.

func (*Tarball) SaveData

func (t *Tarball) SaveData() ([]byte, error)

SaveData saves written files and returns the tarball data. Once SaveData method is executed, this instance cannot be used anymore.

type Version

type Version struct {
	Major     int
	Minor     int
	Patch     int
	Qualifier string
}

func ParseVersion

func ParseVersion(version string) Version

func (*Version) Equivalent

func (a *Version) Equivalent(b Version) bool

func (*Version) IsUndefined

func (v *Version) IsUndefined() bool

func (*Version) LessRecentThan

func (a *Version) LessRecentThan(b Version) bool

func (*Version) MoreRecentThan

func (a *Version) MoreRecentThan(b Version) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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