utils

package
v0.4.10 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: GPL-2.0 Imports: 17 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 ContainsPrefix added in v0.4.0

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

ContainsPrefix checks a list has a value with the prefixes

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 GetVersionIncrement added in v0.4.0

func GetVersionIncrement(version string) (string, error)

GetVersionIncrement returns either an error or the version increment

func LatestSemverVersion added in v0.4.0

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

LatestSemverVersion returns the latest semver version from a list of versions.

func ListKeys added in v0.3.25

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

ListKeys return a list of keys from a map

func LoadYAML added in v0.4.0

func LoadYAML(path string, data interface{}) error

LoadYAML loads a yaml document into a structure

func LoadYAMLFromReader added in v0.4.0

func LoadYAMLFromReader(reader io.Reader, data interface{}) error

LoadYAMLFromReader loads a yaml document from a io reader

func MaxChars added in v0.4.0

func MaxChars(slice string, max int) string

MaxChars returns the maximum character length of a list of strings

func MergeStringMaps

func MergeStringMaps(list ...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 ToMap added in v0.4.1

func ToMap(slice []string) (map[string]string, error)

ToMap converts a list of strings to a map

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 VersionLessThan added in v0.4.0

func VersionLessThan(version string, other string) (bool, error)

VersionLessThan returns either an error a bool indicating if the version is greater than the other

func WaitForFile

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

WaitForFile waits for a file to exist or times out

func WriteYAML added in v0.4.0

func WriteYAML(path string, data interface{}) error

WriteYAML writes a yaml document to a file

func WriteYAMLToWriter added in v0.4.0

func WriteYAMLToWriter(writer io.Writer, data interface{}) error

WriteYAMLToWriter writes a yaml document to a writer

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