utils

package
v0.0.0-...-b2ebdcc Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 12 Imported by: 5

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 NewSpinner

func NewSpinner(message string, maxRetries int, function func() error) error

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