utils

package
v0.3.19 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 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 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 TempDirName

func TempDirName() string

TempDirName creates a temporary directory

func TouchFile

func TouchFile(path string) error

TouchFile is used to create a file

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

Jump to

Keyboard shortcuts

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