utils

package
v0.3.28 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: GPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultCharSet is the default charset to use
	DefaultCharSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)
View Source
const (
	// MaxAttempts is the max attempts
	MaxAttempts = 99999999
)

Variables

View Source
var (
	// ErrCancelled indicates the operation was cancelled
	ErrCancelled = errors.New("operation cancelled")
	// ErrReachMaxAttempts indicates we hit the limit
	ErrReachMaxAttempts = errors.New("reached max attempts")
)

Functions

func ByteCountSI

func ByteCountSI(b int64) string

ByteCountSI returns the number of bytes in the given number of SI units.

func Contains

func Contains(v string, l []string) bool

Contains checks a list has a value in it

func ContainsList

func ContainsList(v []string, l []string) bool

ContainsList checks a list has a value in it

func DirExists

func DirExists(path string) (bool, error)

DirExists checks if the directory exists

func DirSize

func DirSize(path string) (int64, error)

DirSize returns the size of the directory

func Download

func Download(ctx context.Context, source, destination string) error

Download retrieves a source assets using the go-getter library

func FileExists

func FileExists(filename string) (bool, error)

FileExists checks if a file exists

func GetEnv added in v0.3.24

func GetEnv(key, fallback string) string

GetEnv returns the value of an environment variable or a default value if not set

func ListKeys added in v0.3.25

func ListKeys(m map[string]any) []string

ListKeys return a list of keys from a map

func MergeStringMaps

func MergeStringMaps(a, b map[string]string) map[string]string

MergeStringMaps merges maps together

func Random

func Random(length int) string

Random returns a random string

func RandomWithCharset

func RandomWithCharset(length int, charset string) string

RandomWithCharset returns a random string of x charset

func Retry

func Retry(ctx context.Context, attempts int, jitter bool, minInterval time.Duration, retryFn RetryFunc) error

Retry is used to retry an operation multiple times under a context. If the retryFn returns false with no error, the operation will be retried.

func RetryWithTimeout

func RetryWithTimeout(ctx context.Context, timeout, interval time.Duration, retryFn RetryFunc) error

RetryWithTimeout creates a retry with a specific timeout

func Sleep

func Sleep(ctx context.Context, sleep time.Duration) bool

Sleep provides a default sleep but with a cancellable context

func SortSemverVersions

func SortSemverVersions(versions []string) ([]string, error)

SortSemverVersions sorts a list of semver versions in ascending order.

func Sorted added in v0.3.25

func Sorted(slice []string) []string

Sorted returns a sorted list of values

func TempDirName

func TempDirName() string

TempDirName creates a temporary directory

func TouchFile

func TouchFile(path string) error

TouchFile is used to create a file

func Unique added in v0.3.25

func Unique(slice []string) []string

Unique returns a list of unique values

func WaitForFile

func WaitForFile(ctx context.Context, path string, timeout time.Duration) error

WaitForFile waits for a file to exist or times out

func YAMLDocuments

func YAMLDocuments(reader io.Reader) ([]string, error)

YAMLDocuments returns a collection of documents from the reader

Types

type RetryFunc

type RetryFunc func() (bool, error)

RetryFunc performs the operation. It should return true if the operation is complete, false if it should be retried, and an error if an error which should NOT be retried has occurred.

Directories

Path Synopsis
eks
eks/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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