Documentation ¶
Overview ¶
Package utils is used for common functions and tools used across the codebase.
Index ¶
- Constants
- Variables
- func AddHexPrefix(str string) string
- func AllEqual[T comparable](elems ...T) bool
- func BatchSplit[T any](list []T, max int) (out [][]T, err error)
- func BoxOutput(errorMsgTemplate string, errorMsgValues ...interface{}) string
- func Bytes32FromString(s string) [32]byte
- func Bytes32ToSlice(a [32]byte) (r []byte)
- func Bytes4FromString(s string) [4]byte
- func CheckPasswordHash(password, hash string) bool
- func CheckUint256(n *big.Int) error
- func ConcatBytes(bufs ...[]byte) []byte
- func ContextFromChan(chStop <-chan struct{}) (context.Context, context.CancelFunc)
- func ContextFromChanWithDeadline(chStop <-chan struct{}, timeout time.Duration) (context.Context, context.CancelFunc)
- func DurationFromNow(t time.Time) time.Duration
- func EIP55CapitalizedAddress(possibleAddressString string) bool
- func EVMBytesToUint64(buf []byte) uint64
- func EVMEncodeBytes(input []byte) []byte
- func EVMTranscodeBool(value gjson.Result) ([]byte, error)
- func EVMTranscodeInt256(value gjson.Result) ([]byte, error)
- func EVMTranscodeUint256(value gjson.Result) ([]byte, error)
- func EVMWordBigInt(val *big.Int) ([]byte, error)
- func EVMWordSignedBigInt(val *big.Int) ([]byte, error)
- func EVMWordUint128(val *big.Int) ([]byte, error)
- func EVMWordUint32(val uint32) []byte
- func EVMWordUint64(val uint64) []byte
- func EnsureDirAndMaxPerms(path string, perms os.FileMode) error
- func EnsureFileMaxPerms(file *os.File, perms os.FileMode) error
- func EnsureFilepathMaxPerms(filepath string, perms os.FileMode) (err error)
- func FileExists(name string) bool
- func FiniteTicker(period time.Duration, onTick func()) func()
- func FormatJSON(v interface{}) ([]byte, error)
- func GenericEncode(types []string, values ...interface{}) ([]byte, error)
- func HasHexPrefix(str string) bool
- func HashPassword(password string) (string, error)
- func HexToBig(s string) *big.Int
- func HexToUint256(s string) (*big.Int, error)
- func ISO8601UTC(t time.Time) string
- func IsEmpty(bytes []byte) bool
- func IsEmptyAddress(addr common.Address) bool
- func IsFileOwnedByChainlink(fileInfo os.FileInfo) (bool, error)
- func IsQuoted(input []byte) bool
- func JustError(_ interface{}, err error) error
- func Keccak256(in []byte) ([]byte, error)
- func Keccak256Fixed(in []byte) [32]byte
- func LeftPadBitString(input string, length int) string
- func MaxInt(first int, ints ...int) int
- func MaxUint32(first uint32, uints ...uint32) uint32
- func MinUint(first uint, vals ...uint) uint
- func MustAbiType(ts string, components []abi.ArgumentMarshaling) abi.Type
- func MustHash(in string) common.Hash
- func MustNewPeerID() string
- func MustUnmarshalToMap(input string) map[string]interface{}
- func NewBytes32ID() string
- func NewHash() common.Hash
- func NewRedialBackoff() backoff.Backoff
- func NewSecret(n int) string
- func NormalizedJSON(val []byte) (string, error)
- func PadByteToHash(b byte) common.Hash
- func ParseEthereumAddress(addressString string) (common.Address, error)
- func RandUint256() *big.Int
- func RandomAddress() common.Address
- func RandomBytes32() (r [32]byte)
- func RemoveHexPrefix(str string) string
- func RemoveQuotes(input []byte) []byte
- func RetryWithBackoff(ctx context.Context, fn func() (retry bool))
- func Sha256(in string) (string, error)
- func StringToHex(in string) string
- func ToDecimal(input interface{}) (decimal.Decimal, error)
- func TooPermissive(fileMode, maxAllowedPerms os.FileMode) bool
- func TryParseHex(s string) (b []byte, err error)
- func Uint256ToBytes(x *big.Int) (uint256 []byte, err error)
- func Uint256ToBytes32(n *big.Int) []byte
- func UnmarshalToMap(input string) (map[string]interface{}, error)
- func ValidateCronSchedule(schedule string) error
- func VerifyPasswordComplexity(password string) (merr error)
- func WaitGroupChan(wg *sync.WaitGroup) <-chan struct{}
- func WithCloseChan(parentCtx context.Context, chStop <-chan struct{}) (ctx context.Context, cancel context.CancelFunc)
- func WithJitter(d time.Duration) time.Duration
- func WrapIfError(err *error, msg string)
- func WriteFileWithMaxPerms(path string, data []byte, perms os.FileMode) (err error)
- type BackoffSleeper
- type BackoffTicker
- type Big
- func (b *Big) Add(c interface{}) *Big
- func (b *Big) Bytes() []byte
- func (b *Big) Cmp(c *Big) int
- func (b *Big) Equal(c *Big) bool
- func (b *Big) Hex() string
- func (b *Big) Int64() int64
- func (b Big) MarshalJSON() ([]byte, error)
- func (b Big) MarshalText() ([]byte, error)
- func (b *Big) Mod(c interface{}) *Big
- func (b *Big) Scan(value interface{}) error
- func (b *Big) String() string
- func (b *Big) Sub(c interface{}) *Big
- func (b *Big) ToInt() *big.Int
- func (b *Big) UnmarshalJSON(input []byte) error
- func (b *Big) UnmarshalText(input []byte) error
- func (b Big) Value() (driver.Value, error)
- type BigFloat
- type BoundedPriorityQueue
- type BoundedQueue
- type CronTicker
- type DependentAwaiter
- type DiskStatsProvider
- type FileSize
- type KeyedMutex
- type LazyLoad
- type Mailbox
- type PausableTicker
- type ResettableTimer
- type ScryptConfigReader
- type ScryptParams
- type Sleeper
- type SleeperTask
- type StartStopOnce
- func (once *StartStopOnce) Healthy() error
- func (once *StartStopOnce) IfNotStopped(f func()) (ok bool)
- func (once *StartStopOnce) IfStarted(f func()) (ok bool)
- func (once *StartStopOnce) Ready() error
- func (once *StartStopOnce) StartOnce(name string, fn func() error) error
- func (once *StartStopOnce) State() StartStopOnceState
- func (once *StartStopOnce) StopOnce(name string, fn func() error) error
- type StartStopOnceState
- type TickerBase
- type Worker
Constants ¶
const ( // FormatBytes encodes the output as bytes FormatBytes = "bytes" // FormatPreformatted encodes the output, assumed to be hex, as bytes. FormatPreformatted = "preformatted" // FormatUint256 encodes the output as bytes containing a uint256 FormatUint256 = "uint256" // FormatInt256 encodes the output as bytes containing an int256 FormatInt256 = "int256" // FormatBool encodes the output as bytes containing a bool FormatBool = "bool" )
const ( KB = 1000 MB = 1000 * KB GB = 1000 * MB TB = 1000 * GB )
nolint
const ( // FastN is a shorter N parameter for testing FastN = 2 // FastP is a shorter P parameter for testing FastP = 1 )
const ( // DefaultSecretSize is the entropy in bytes to generate a base64 string of 64 characters. DefaultSecretSize = 48 // EVMWordByteLen the length of an EVM Word Byte EVMWordByteLen = 32 )
const PasswordComplexityRequirements = `` /* 308-byte string literal not displayed */
Variables ¶
var ( // MaxUint256 represents the largest number represented by an EVM word MaxUint256 = &big.Int{} // MaxInt256 represents the largest number represented by an EVM word using // signed encoding. MaxInt256 = &big.Int{} // MinInt256 represents the smallest number represented by an EVM word using // signed encoding. MinInt256 = &big.Int{} )
"Constants" used by EVM words
var ( ErrPasswordMinLength = errors.New("must be longer than 12 characters") ErrPasswordMinLowercase = errors.New("must contain at least 3 lowercase characters") ErrPasswordMinUppercase = errors.New("must contain at least 3 uppercase characters") ErrPasswordMinNumbers = errors.New("must contain at least 3 numbers") ErrPasswordMinSymbols = errors.New("must contain at least 3 symbols") ErrPasswordRepeatedChars = errors.New("must not contain more than 3 identical consecutive characters") )
var DefaultScryptParams = ScryptParams{N: keystore.StandardScryptN, P: keystore.StandardScryptP}
DefaultScryptParams is for use in production. It used geth's standard level of encryption and is relatively expensive to decode. Avoid using this in tests.
var EmptyHash = common.Hash{}
EmptyHash is a hash of all zeroes, otherwise in Ethereum as 0x0000000000000000000000000000000000000000000000000000000000000000
var FastScryptParams = ScryptParams{N: FastN, P: FastP}
FastScryptParams is for use in tests, where you don't want to wear out your CPU with expensive key derivations, do not use it in production, or your encrypted keys will be easy to brute-force!
var ZeroAddress = common.Address{}
ZeroAddress is an address of all zeroes, otherwise in Ethereum as 0x0000000000000000000000000000000000000000
Functions ¶
func AddHexPrefix ¶
AddHexPrefix adds the prefix (0x) to a given hex string.
func AllEqual ¶ added in v1.4.0
func AllEqual[T comparable](elems ...T) bool
AllEqual returns true iff all the provided elements are equal to each other.
func BatchSplit ¶ added in v1.5.0
BatchSplit splits an slices into an slices of slicess with a maximum length
func BoxOutput ¶ added in v0.10.11
BoxOutput formats its arguments as fmt.Printf, and encloses them in a box of arrows pointing at their content, in order to better highlight it. See ExampleBoxOutput
func Bytes32FromString ¶ added in v0.10.9
Bytes32FromString returns a 32 byte array filled from the given string, which may be of any length.
func Bytes32ToSlice ¶ added in v1.5.0
func Bytes4FromString ¶ added in v0.10.9
Bytes4FromString returns a 4 byte array filled from the given string, which may be of any length.
func CheckPasswordHash ¶
CheckPasswordHash wraps around bcrypt.CompareHashAndPassword for a friendlier API.
func CheckUint256 ¶ added in v0.8.2
CheckUint256 returns an error if n is out of bounds for a uint256
func ConcatBytes ¶
ConcatBytes appends a bunch of byte arrays into a single byte array
func ContextFromChan ¶ added in v0.9.3
func ContextFromChan(chStop <-chan struct{}) (context.Context, context.CancelFunc)
ContextFromChan creates a context that finishes when the provided channel receives or is closed. When channel closes, the ctx.Err() will always be context.Canceled NOTE: Spins up a goroutine that exits on cancellation. REMEMBER TO CALL CANCEL OTHERWISE IT CAN LEAD TO MEMORY LEAKS
func ContextFromChanWithDeadline ¶ added in v1.1.0
func ContextFromChanWithDeadline(chStop <-chan struct{}, timeout time.Duration) (context.Context, context.CancelFunc)
ContextFromChanWithDeadline creates a context with a deadline that finishes when the provided channel receives or is closed. NOTE: Spins up a goroutine that exits on cancellation. REMEMBER TO CALL CANCEL OTHERWISE IT CAN LEAD TO MEMORY LEAKS
func DurationFromNow ¶
DurationFromNow returns the amount of time since the Time field was last updated.
func EIP55CapitalizedAddress ¶
EIP55CapitalizedAddress returns true iff possibleAddressString has the correct capitalization for an Ethereum address, per EIP 55
func EVMBytesToUint64 ¶ added in v0.9.0
EVMBytesToUint64 converts a bytebuffer to uint64
func EVMEncodeBytes ¶
EVMEncodeBytes encodes arbitrary bytes as bytes expected by the EVM
func EVMTranscodeBool ¶
EVMTranscodeBool converts a json input to an EVM bool
func EVMTranscodeInt256 ¶
EVMTranscodeInt256 converts a json input to an EVM int256
func EVMTranscodeUint256 ¶
EVMTranscodeUint256 converts a json input to an EVM uint256
func EVMWordBigInt ¶
EVMWordBigInt returns a big.Int as an EVM word byte array, with support for a signed representation. Returns error on overflow.
func EVMWordSignedBigInt ¶
EVMWordSignedBigInt returns a big.Int as an EVM word byte array, with support for a signed representation. Returns error on overflow.
func EVMWordUint128 ¶ added in v0.8.2
EVMWordUint128 returns a uint128 as an EVM word byte array.
func EVMWordUint32 ¶ added in v1.0.0
EVMWordUint32 returns a uint32 as an EVM word byte array.
func EVMWordUint64 ¶
EVMWordUint64 returns a uint64 as an EVM word byte array.
func EnsureDirAndMaxPerms ¶ added in v0.8.5
EnsureDirAndMaxPerms ensures that the given path exists, that it's a directory, and that it has permissions that are no more permissive than the given ones.
- If the path does not exist, it is created - If the path exists, but is not a directory, an error is returned - If the path exists, and is a directory, but has the wrong perms, it is chmod'ed
func EnsureFileMaxPerms ¶ added in v0.8.5
EnsureFileMaxPerms ensures that the given file has permissions that are no more permissive than the given ones.
func EnsureFilepathMaxPerms ¶ added in v0.8.5
EnsureFilepathMaxPerms ensures that the file at the given filepath has permissions that are no more permissive than the given ones.
func FileExists ¶
FileExists returns true if a file at the passed string exists.
func FiniteTicker ¶ added in v1.1.0
FiniteTicker starts a goroutine to execute the given function periodically, until the returned function is called.
func FormatJSON ¶
FormatJSON applies indent to format a JSON response.
func GenericEncode ¶ added in v1.0.0
GenericEncode eth encodes values based on the provided types
func HasHexPrefix ¶
HasHexPrefix returns true if the string starts with 0x.
func HashPassword ¶
HashPassword wraps around bcrypt.GenerateFromPassword for a friendlier API.
func HexToUint256 ¶ added in v0.8.2
HexToUint256 returns the uint256 represented by s, or an error if it doesn't represent one.
func IsEmpty ¶ added in v0.10.4
IsEmpty returns true if bytes contains only zero values, or has len 0.
func IsEmptyAddress ¶
IsEmptyAddress checks that the address is empty, synonymous with the zero account/address. No logs can come from this address, as there is no contract present there.
See https://stackoverflow.com/questions/48219716/what-is-address0-in-solidity for the more info on the zero address.
func IsFileOwnedByChainlink ¶ added in v0.8.9
IsFileOwnedByChainlink attempts to read fileInfo to verify file owner
func Keccak256 ¶
Keccak256 is a simplified interface for the legacy SHA3 implementation that Ethereum uses.
func Keccak256Fixed ¶ added in v1.5.0
func LeftPadBitString ¶ added in v1.5.0
func MustAbiType ¶ added in v1.5.0
func MustAbiType(ts string, components []abi.ArgumentMarshaling) abi.Type
func MustNewPeerID ¶ added in v1.5.0
func MustNewPeerID() string
func MustUnmarshalToMap ¶ added in v0.8.17
MustUnmarshalToMap performs UnmarshalToMap, panics upon failure
func NewBytes32ID ¶
func NewBytes32ID() string
NewBytes32ID returns a randomly generated UUID that conforms to Ethereum bytes32.
func NewRedialBackoff ¶ added in v1.3.0
NewRedialBackoff is a standard backoff to use for redialling or reconnecting to unreachable network endpoints
func NewSecret ¶ added in v0.6.6
NewSecret returns a new securely random sequence of n bytes of entropy. The result is a base64 encoded string.
Panics on failed attempts to read from system's PRNG.
func NormalizedJSON ¶
NormalizedJSON returns a JSON representation of an object that has been normalized to produce a consistent output for hashing.
NOTE: If this string is unmarshalled again, there is no guarantee that the final representation will be consistent with the string produced by this function due to differences in JSON implementations and information loss. e.g:
JSON does not have a requirement to respect object key ordering.
func PadByteToHash ¶ added in v0.10.11
PadByteToHash returns a hash with zeros padded on the left of the given byte.
func ParseEthereumAddress ¶
ParseEthereumAddress returns addressString as a go-ethereum Address, or an error if it's invalid, e.g. if EIP 55 capitalization check fails
func RandUint256 ¶ added in v1.5.0
RandUint256 generates a random bigNum up to 2 ** 256 - 1
func RandomAddress ¶ added in v1.5.0
func RandomBytes32 ¶ added in v1.5.0
func RandomBytes32() (r [32]byte)
func RemoveHexPrefix ¶
RemoveHexPrefix removes the prefix (0x) of a given hex string.
func RemoveQuotes ¶
RemoveQuotes removes the first and last character if they are both either " or ', otherwise it is a noop.
func RetryWithBackoff ¶ added in v0.8.3
RetryWithBackoff retries the sleeper and backs off if not Done
func StringToHex ¶
StringToHex converts a standard string to a hex encoded string.
func TooPermissive ¶ added in v0.8.5
TooPermissive checks if the file has more than the allowed permissions
func TryParseHex ¶ added in v1.5.0
TryParseHex parses the given hex string to bytes, it can return error if the hex string is invalid. Follows the semantic of ethereum's FromHex.
func Uint256ToBytes ¶ added in v0.8.2
Uint256ToBytes is x represented as the bytes of a uint256
func Uint256ToBytes32 ¶ added in v0.10.8
Uint256ToBytes32 returns the bytes32 encoding of the big int provided
func UnmarshalToMap ¶ added in v0.8.17
UnmarshalToMap takes an input json string and returns a map[string]interface i.e. a raw object
func ValidateCronSchedule ¶ added in v0.10.10
ValidateCronSchedule returns an error if the given schedule is invalid.
func VerifyPasswordComplexity ¶ added in v1.5.0
func WaitGroupChan ¶ added in v0.8.3
WaitGroupChan creates a channel that closes when the provided sync.WaitGroup is done.
func WithCloseChan ¶ added in v1.3.0
func WithCloseChan(parentCtx context.Context, chStop <-chan struct{}) (ctx context.Context, cancel context.CancelFunc)
WithCloseChan wraps a context so that it is canceled if the passed in channel is closed. NOTE: Spins up a goroutine that exits on cancellation. REMEMBER TO CALL CANCEL OTHERWISE IT CAN LEAD TO MEMORY LEAKS
func WithJitter ¶ added in v0.9.6
WithJitter adds +/- 10% to a duration
func WrapIfError ¶ added in v0.8.13
WrapIfError decorates an error with the given message. It is intended to be used with `defer` statements, like so:
func SomeFunction() (err error) { defer WrapIfError(&err, "error in SomeFunction:") ... }
Types ¶
type BackoffSleeper ¶
BackoffSleeper is a sleeper that backs off on subsequent attempts.
func NewBackoffSleeper ¶
func NewBackoffSleeper() *BackoffSleeper
NewBackoffSleeper returns a BackoffSleeper that is configured to sleep for 0 seconds initially, then backs off from 1 second minimum to 10 seconds maximum.
func (*BackoffSleeper) After ¶
func (bs *BackoffSleeper) After() time.Duration
After returns the duration for the next stop, and increments the backoff.
func (*BackoffSleeper) Duration ¶
func (bs *BackoffSleeper) Duration() time.Duration
Duration returns the current duration value.
func (*BackoffSleeper) Reset ¶
func (bs *BackoffSleeper) Reset()
Reset resets the backoff intervals.
func (*BackoffSleeper) Sleep ¶
func (bs *BackoffSleeper) Sleep()
Sleep waits for the given duration, incrementing the back off.
type BackoffTicker ¶ added in v0.10.5
BackoffTicker sends ticks with periods that increase over time, over a configured range.
func NewBackoffTicker ¶ added in v0.10.5
func NewBackoffTicker(min, max time.Duration) BackoffTicker
NewBackoffTicker returns a new BackoffTicker for the given range.
func (*BackoffTicker) Bounds ¶ added in v0.10.8
func (t *BackoffTicker) Bounds() (time.Duration, time.Duration)
func (*BackoffTicker) Start ¶ added in v0.10.5
func (t *BackoffTicker) Start() bool
Start - Starts the ticker Returns true if the ticker was not running yet
func (*BackoffTicker) Stop ¶ added in v0.10.5
func (t *BackoffTicker) Stop() bool
Stop stops the ticker. A ticker can be restarted by calling Start on a stopped ticker. Returns true if the ticker was actually stopped at this invocation (was previously running)
func (*BackoffTicker) Ticks ¶ added in v0.10.5
func (t *BackoffTicker) Ticks() <-chan time.Time
Ticks returns the underlying channel.
type Big ¶ added in v0.8.2
Big stores large integers and can deserialize a variety of inputs.
func (Big) MarshalJSON ¶ added in v0.8.2
MarshalJSON marshals this instance to base 10 number as string.
func (Big) MarshalText ¶ added in v0.8.2
MarshalText marshals this instance to base 10 number as string.
func (*Big) UnmarshalJSON ¶ added in v0.8.2
UnmarshalJSON implements encoding.JSONUnmarshaler.
func (*Big) UnmarshalText ¶ added in v0.8.2
UnmarshalText implements encoding.TextUnmarshaler.
type BigFloat ¶ added in v0.8.2
BigFloat accepts both string and float JSON values.
func (BigFloat) MarshalJSON ¶ added in v0.8.2
MarshalJSON implements the json.Marshaler interface.
func (*BigFloat) UnmarshalJSON ¶ added in v0.8.2
UnmarshalJSON implements the json.Unmarshal interface.
type BoundedPriorityQueue ¶ added in v0.8.3
type BoundedPriorityQueue[T any] struct { // contains filtered or unexported fields }
BoundedPriorityQueue stores a series of BoundedQueues with associated priorities and capacities
func NewBoundedPriorityQueue ¶ added in v0.8.3
func NewBoundedPriorityQueue[T any](capacities map[uint]int) *BoundedPriorityQueue[T]
NewBoundedPriorityQueue creates a new BoundedPriorityQueue
func (*BoundedPriorityQueue[T]) Add ¶ added in v0.8.3
func (q *BoundedPriorityQueue[T]) Add(priority uint, x T)
Add pushes an item into a subque within a BoundedPriorityQueue
func (*BoundedPriorityQueue[T]) Empty ¶ added in v0.8.3
func (q *BoundedPriorityQueue[T]) Empty() bool
Empty checks the BoundedPriorityQueue if all subqueues are empty
func (*BoundedPriorityQueue[T]) Take ¶ added in v0.8.3
func (q *BoundedPriorityQueue[T]) Take() (t T)
Take takes from the BoundedPriorityQueue's subque
type BoundedQueue ¶ added in v0.8.3
type BoundedQueue[T any] struct { // contains filtered or unexported fields }
BoundedQueue is a FIFO queue that discards older items when it reaches its capacity.
func NewBoundedQueue ¶ added in v0.8.3
func NewBoundedQueue[T any](capacity int) *BoundedQueue[T]
NewBoundedQueue creates a new BoundedQueue instance
func (*BoundedQueue[T]) Add ¶ added in v0.8.3
func (q *BoundedQueue[T]) Add(x T)
Add appends items to a BoundedQueue
func (*BoundedQueue[T]) Empty ¶ added in v0.8.3
func (q *BoundedQueue[T]) Empty() bool
Empty check is a BoundedQueue is empty
func (*BoundedQueue[T]) Full ¶ added in v0.8.3
func (q *BoundedQueue[T]) Full() bool
Full checks if a BoundedQueue is over capacity.
func (*BoundedQueue[T]) Take ¶ added in v0.8.3
func (q *BoundedQueue[T]) Take() (t T)
Take pulls the first item from the array and removes it
type CronTicker ¶ added in v0.10.10
type CronTicker struct { *cron.Cron // contains filtered or unexported fields }
CronTicker is like a time.Ticker but for a cron schedule.
func NewCronTicker ¶ added in v0.10.10
func NewCronTicker(schedule string) (CronTicker, error)
NewCronTicker returns a new CrontTicker for the given schedule.
func (*CronTicker) Start ¶ added in v0.10.10
func (t *CronTicker) Start() bool
Start - returns true if the CronTicker was actually started, false otherwise
func (*CronTicker) Stop ¶ added in v0.10.10
func (t *CronTicker) Stop() bool
Stop - returns true if the CronTicker was actually stopped, false otherwise
func (*CronTicker) Ticks ¶ added in v0.10.10
func (t *CronTicker) Ticks() <-chan time.Time
Ticks returns the underlying chanel.
type DependentAwaiter ¶ added in v0.8.3
type DependentAwaiter interface { AwaitDependents() <-chan struct{} AddDependents(n int) DependentReady() }
DependentAwaiter contains Dependent funcs
func NewDependentAwaiter ¶ added in v0.8.3
func NewDependentAwaiter() DependentAwaiter
NewDependentAwaiter creates a new DependentAwaiter
type DiskStatsProvider ¶ added in v1.3.0
DiskStatsProvider describes the abstraction to the `shirou/gopsutil/v3` for mocking purposes
func NewDiskStatsProvider ¶ added in v1.3.0
func NewDiskStatsProvider() DiskStatsProvider
NewDiskStatsProvider returns a new `DiskStatsProvider` instance
type FileSize ¶ added in v1.1.0
type FileSize uint64
FileSize repesents a file size in bytes.
func (FileSize) MarshalText ¶ added in v1.1.0
MarshalText encodes s as a human readable string.
func (*FileSize) UnmarshalText ¶ added in v1.1.0
UnmarshalText parses a file size from bs in to s.
type KeyedMutex ¶ added in v0.10.9
type KeyedMutex struct {
// contains filtered or unexported fields
}
KeyedMutex allows to lock based on particular values
func (*KeyedMutex) LockInt64 ¶ added in v0.10.9
func (m *KeyedMutex) LockInt64(key int64) func()
LockInt64 locks the value for read/write
type LazyLoad ¶ added in v1.5.0
type LazyLoad[T any] struct { // contains filtered or unexported fields }
func NewLazyLoad ¶ added in v1.5.0
type Mailbox ¶ added in v0.10.0
type Mailbox[T any] struct { // contains filtered or unexported fields }
Mailbox contains a notify channel, a mutual exclusive lock, a queue of interfaces, and a queue capacity.
func NewHighCapacityMailbox ¶ added in v1.0.0
NewHighCapacityMailbox create a new mailbox with a capacity that is better able to handle e.g. large log replays
func NewMailbox ¶ added in v0.10.0
NewMailbox creates a new mailbox instance
func (*Mailbox[T]) Notify ¶ added in v0.10.0
func (m *Mailbox[T]) Notify() chan struct{}
Notify returns the contents of the notify channel
func (*Mailbox[T]) RetrieveLatestAndClear ¶ added in v0.10.3
func (m *Mailbox[T]) RetrieveLatestAndClear() (t T)
RetrieveLatestAndClear returns the latest value (or nil), and clears the queue.
type PausableTicker ¶ added in v0.9.0
type PausableTicker struct {
// contains filtered or unexported fields
}
PausableTicker stores a ticker with a duration
func NewPausableTicker ¶ added in v0.9.0
func NewPausableTicker(duration time.Duration) PausableTicker
NewPausableTicker creates a new PausableTicker
func (*PausableTicker) Destroy ¶ added in v0.9.0
func (t *PausableTicker) Destroy()
Destroy pauses the PausibleTicker
func (*PausableTicker) Pause ¶ added in v0.9.0
func (t *PausableTicker) Pause()
Pause pauses a PausableTicker
func (*PausableTicker) Resume ¶ added in v0.9.0
func (t *PausableTicker) Resume()
Resume resumes a Ticker using a PausibleTicker's duration
func (*PausableTicker) Ticks ¶ added in v0.9.0
func (t *PausableTicker) Ticks() <-chan time.Time
Ticks retrieves the ticks from a PausableTicker
type ResettableTimer ¶ added in v0.9.0
type ResettableTimer struct {
// contains filtered or unexported fields
}
ResettableTimer stores a timer
func NewResettableTimer ¶ added in v0.9.0
func NewResettableTimer() ResettableTimer
NewResettableTimer creates a new ResettableTimer
func (*ResettableTimer) Reset ¶ added in v0.9.0
func (t *ResettableTimer) Reset(duration time.Duration)
Reset stops a ResettableTimer and resets it with a new duration
func (*ResettableTimer) Stop ¶ added in v0.9.0
func (t *ResettableTimer) Stop()
Stop stops a ResettableTimer
func (*ResettableTimer) Ticks ¶ added in v0.9.0
func (t *ResettableTimer) Ticks() <-chan time.Time
Ticks retrieves the ticks from a ResettableTimer
type ScryptConfigReader ¶ added in v0.9.3
type ScryptConfigReader interface {
InsecureFastScrypt() bool
}
ScryptConfigReader can check for an insecure, fast flag
type ScryptParams ¶ added in v0.9.3
type ScryptParams struct{ N, P int }
ScryptParams represents two integers, N and P.
func GetScryptParams ¶ added in v0.9.3
func GetScryptParams(config ScryptConfigReader) ScryptParams
GetScryptParams fetches ScryptParams from a ScryptConfigReader
type Sleeper ¶
Sleeper interface is used for tasks that need to be done on some interval, excluding Cron, like reconnecting.
type SleeperTask ¶ added in v0.9.3
type SleeperTask interface { Stop() error WakeUp() WakeUpIfStarted() }
SleeperTask represents a task that waits in the background to process some work.
func NewSleeperTask ¶ added in v0.9.3
func NewSleeperTask(worker Worker) SleeperTask
NewSleeperTask takes a worker and returns a SleeperTask.
SleeperTask is guaranteed to call Work on the worker at least once for every WakeUp call. If the Worker is busy when WakeUp is called, the Worker will be called again immediately after it is finished. For this reason you should take care to make sure that Worker is idempotent. WakeUp does not block.
type StartStopOnce ¶ added in v0.9.3
type StartStopOnce struct { sync.RWMutex // lock is held during startup/shutdown, RLock is held while executing functions dependent on a particular state // contains filtered or unexported fields }
StartStopOnce contains a StartStopOnceState integer
func (*StartStopOnce) Healthy ¶ added in v0.10.8
func (once *StartStopOnce) Healthy() error
Healthy returns ErrNotStarted if the state is not started. Override this per-service with more specific implementations.
func (*StartStopOnce) IfNotStopped ¶ added in v1.2.0
func (once *StartStopOnce) IfNotStopped(f func()) (ok bool)
IfNotStopped runs the func and returns true if in any state other than Stopped
func (*StartStopOnce) IfStarted ¶ added in v0.10.5
func (once *StartStopOnce) IfStarted(f func()) (ok bool)
IfStarted runs the func and returns true only if started, otherwise returns false
func (*StartStopOnce) Ready ¶ added in v0.10.8
func (once *StartStopOnce) Ready() error
Ready returns ErrNotStarted if the state is not started.
func (*StartStopOnce) StartOnce ¶ added in v0.9.3
func (once *StartStopOnce) StartOnce(name string, fn func() error) error
StartOnce sets the state to Started
func (*StartStopOnce) State ¶ added in v0.9.3
func (once *StartStopOnce) State() StartStopOnceState
State retrieves the current state
type StartStopOnceState ¶ added in v0.9.3
type StartStopOnceState int32
StartStopOnceState holds the state for StartStopOnce
const ( StartStopOnce_Unstarted StartStopOnceState = iota StartStopOnce_Started StartStopOnce_Starting StartStopOnce_Stopping StartStopOnce_Stopped )
nolint
func (StartStopOnceState) String ¶ added in v1.3.0
func (s StartStopOnceState) String() string
type TickerBase ¶ added in v0.10.14
TickerBase is an interface for pausable tickers.
type Worker ¶ added in v0.9.3
type Worker interface { Work() Name() string }
Worker is a simple interface that represents some work to do repeatedly
func SleeperFuncTask ¶ added in v1.1.0
SleeperFuncTask returns a Worker to execute the given work function.