utils

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultStr

func DefaultStr(values ...string) string

DefaultStr returns the first non-empty string

func EquivalentVersion

func EquivalentVersion(a string, b string) bool

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 RandomId

func RandomId(length int) 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 immediatelly 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 immediatelly on errors, and if the retries are exausted 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 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 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