{"modulePath":"github.com/GoPlugin/pluginV2","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package utils\n\nPackage utils is used for common functions and tools used across the codebase.\n\n## Constants\n\n```go\nconst (\n\t// FormatBytes encodes the output as bytes\n\tFormatBytes = \"bytes\"\n\t// FormatPreformatted encodes the output, assumed to be hex, as bytes.\n\tFormatPreformatted = \"preformatted\"\n\t// FormatUint256 encodes the output as bytes containing a uint256\n\tFormatUint256 = \"uint256\"\n\t// FormatInt256 encodes the output as bytes containing an int256\n\tFormatInt256 = \"int256\"\n\t// FormatBool encodes the output as bytes containing a bool\n\tFormatBool = \"bool\"\n)\n```\n\n```go\nconst (\n\tKB = 1000\n\tMB = 1000 * KB\n\tGB = 1000 * MB\n\tTB = 1000 * GB\n)\n```\nnolint\n\n```go\nconst (\n\t// FastN is a shorter N parameter for testing\n\tFastN = 2\n\t// FastP is a shorter P parameter for testing\n\tFastP = 1\n)\n```\n\n```go\nconst (\n\t// DefaultSecretSize is the entropy in bytes to generate a base64 string of 64 characters.\n\tDefaultSecretSize = 48\n\t// EVMWordByteLen the length of an EVM Word Byte\n\tEVMWordByteLen = 32\n)\n```\n\n```go\nconst MinRequiredLen = 16\n```\n\n```go\nconst PasswordComplexityRequirements = `\nMust have a length of 16-50 characters\nMust not comprise:\n\tLeading or trailing whitespace (note that a trailing newline in the password file, if present, will be ignored)\n`\n```\nPasswordComplexityRequirements defines the complexity requirements message Note that adding an entropy requirement wouldn't add much, since a 16 character password already has an entropy score of 75 even if it's all lowercase characters\n\n## Variables\n\n```go\nvar (\n\n\t// MaxUint256 represents the largest number represented by an EVM word\n\tMaxUint256 = \u0026big.Int{}\n\t// MaxInt256 represents the largest number represented by an EVM word using\n\t// signed encoding.\n\tMaxInt256 = \u0026big.Int{}\n\t// MinInt256 represents the smallest number represented by an EVM word using\n\t// signed encoding.\n\tMinInt256 = \u0026big.Int{}\n)\n```\n\"Constants\" used by EVM words\n\n```go\nvar (\n\tErrPasswordWhitespace  = errors.New(\"leading/trailing whitespace detected in password\")\n\tErrEmptyPasswordInFile = errors.New(\"detected empty password in password file\")\n)\n```\n\n```go\nvar (\n\tErrMsgHeader = fmt.Sprintf(`\nExpected password complexity:\nMust be at least %d characters long\nMust not comprise:\n\tLeading or trailing whitespace\n\tA user's API email\n\nFaults:\n`, MinRequiredLen)\n\tErrWhitespace = errors.New(\"password contains a leading or trailing whitespace\")\n)\n```\n\n```go\nvar (\n\tErrAlreadyStopped      = errors.New(\"already stopped\")\n\tErrCannotStopUnstarted = errors.New(\"cannot stop unstarted service\")\n)\n```\n\n```go\nvar DefaultScryptParams = ScryptParams{N: keystore.StandardScryptN, P: keystore.StandardScryptP}\n```\nDefaultScryptParams is for use in production. It used geth's standard level of encryption and is relatively expensive to decode. Avoid using this in tests.\n\n```go\nvar EmptyHash = common.Hash{}\n```\nEmptyHash is a hash of all zeroes, otherwise in Ethereum as 0x0000000000000000000000000000000000000000000000000000000000000000\n\n```go\nvar FastScryptParams = ScryptParams{N: FastN, P: FastP}\n```\nFastScryptParams 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!\n\n```go\nvar LeadingWhitespace = regexp.MustCompile(`^\\s+`)\n```\n\n```go\nvar TrailingWhitespace = regexp.MustCompile(`\\s+$`)\n```\n\n```go\nvar ZeroAddress = common.Address{}\n```\nZeroAddress is an address of all zeroes, otherwise in Ethereum as 0x0000000000000000000000000000000000000000\n\n## Functions\n\n```go\nfunc ABIDecode(abiStr string, data []byte) ([]interface{}, error)\n```\nABIEncode is the equivalent of abi.decode. See a full set of examples [https://github.com/ethereum/go-ethereum/blob/420b78659bef661a83c5c442121b13f13288c09f/accounts/abi/packing\\_test.go#L31](https://github.com/ethereum/go-ethereum/blob/420b78659bef661a83c5c442121b13f13288c09f/accounts/abi/packing_test.go#L31)\n\n```go\nfunc ABIEncode(abiStr string, values ...interface{}) ([]byte, error)\n```\nABIEncode is the equivalent of abi.encode. See a full set of examples [https://github.com/ethereum/go-ethereum/blob/420b78659bef661a83c5c442121b13f13288c09f/accounts/abi/packing\\_test.go#L31](https://github.com/ethereum/go-ethereum/blob/420b78659bef661a83c5c442121b13f13288c09f/accounts/abi/packing_test.go#L31)\n\n```go\nfunc AddHexPrefix(str string) string\n```\nAddHexPrefix adds the prefix (0x) to a given hex string.\n\n```go\nfunc AllEqual[T comparable](elems ...T) bool\n```\nAllEqual returns true iff all the provided elements are equal to each other.\n\n```go\nfunc BatchSplit[T any](list []T, max int) (out [][]T, err error)\n```\nBatchSplit splits an slices into an slices of slicess with a maximum length\n\n```go\nfunc BoxOutput(errorMsgTemplate string, errorMsgValues ...interface{}) string\n```\nBoxOutput 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\n\n```go\nfunc Bytes32FromString(s string) [32]byte\n```\nBytes32FromString returns a 32 byte array filled from the given string, which may be of any length.\n\n```go\nfunc Bytes32ToSlice(a [32]byte) (r []byte)\n```\n\n```go\nfunc Bytes4FromString(s string) [4]byte\n```\nBytes4FromString returns a 4 byte array filled from the given string, which may be of any length.\n\n```go\nfunc CheckPasswordHash(password, hash string) bool\n```\nCheckPasswordHash wraps around bcrypt.CompareHashAndPassword for a friendlier API.\n\n```go\nfunc CheckUint256(n *big.Int) error\n```\nCheckUint256 returns an error if n is out of bounds for a uint256\n\n```go\nfunc ConcatBytes(bufs ...[]byte) []byte\n```\nConcatBytes appends a bunch of byte arrays into a single byte array\n\n```go\nfunc ContextFromChan(chStop \u003c-chan struct{}) (context.Context, context.CancelFunc)\n```\nContextFromChan 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\n\n```go\nfunc ContextFromChanWithDeadline(chStop \u003c-chan struct{}, timeout time.Duration) (context.Context, context.CancelFunc)\n```\nContextFromChanWithDeadline 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\n\n```go\nfunc DurationFromNow(t time.Time) time.Duration\n```\nDurationFromNow returns the amount of time since the Time field was last updated.\n\n```go\nfunc EIP55CapitalizedAddress(possibleAddressString string) bool\n```\nEIP55CapitalizedAddress returns true iff possibleAddressString has the correct capitalization for an Ethereum address, per EIP 55\n\n```go\nfunc EVMBytesToUint64(buf []byte) uint64\n```\nEVMBytesToUint64 converts a bytebuffer to uint64\n\n```go\nfunc EVMEncodeBytes(input []byte) []byte\n```\nEVMEncodeBytes encodes arbitrary bytes as bytes expected by the EVM\n\n```go\nfunc EVMTranscodeBool(value gjson.Result) ([]byte, error)\n```\nEVMTranscodeBool converts a json input to an EVM bool\n\n```go\nfunc EVMTranscodeInt256(value gjson.Result) ([]byte, error)\n```\nEVMTranscodeInt256 converts a json input to an EVM int256\n\n```go\nfunc EVMTranscodeUint256(value gjson.Result) ([]byte, error)\n```\nEVMTranscodeUint256 converts a json input to an EVM uint256\n\n```go\nfunc EVMWordBigInt(val *big.Int) ([]byte, error)\n```\nEVMWordBigInt returns a big.Int as an EVM word byte array, with support for a signed representation. Returns error on overflow.\n\n```go\nfunc EVMWordSignedBigInt(val *big.Int) ([]byte, error)\n```\nEVMWordSignedBigInt returns a big.Int as an EVM word byte array, with support for a signed representation. Returns error on overflow.\n\n```go\nfunc EVMWordUint128(val *big.Int) ([]byte, error)\n```\nEVMWordUint128 returns a uint128 as an EVM word byte array.\n\n```go\nfunc EVMWordUint32(val uint32) []byte\n```\nEVMWordUint32 returns a uint32 as an EVM word byte array.\n\n```go\nfunc EVMWordUint64(val uint64) []byte\n```\nEVMWordUint64 returns a uint64 as an EVM word byte array.\n\n```go\nfunc EnsureClosed(c io.Closer) error\n```\nEnsureClosed closes the io.Closer, returning nil if it was already closed or not started yet\n\n```go\nfunc EnsureDirAndMaxPerms(path string, perms os.FileMode) error\n```\nEnsureDirAndMaxPerms 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.\n\n\\- 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\n\n```go\nfunc EnsureFileMaxPerms(file *os.File, perms os.FileMode) error\n```\nEnsureFileMaxPerms ensures that the given file has permissions that are no more permissive than the given ones.\n\n```go\nfunc EnsureFilepathMaxPerms(filepath string, perms os.FileMode) (err error)\n```\nEnsureFilepathMaxPerms ensures that the file at the given filepath has permissions that are no more permissive than the given ones.\n\n```go\nfunc FileExists(name string) (bool, error)\n```\nFileExists returns true if a file at the passed string exists.\n\n```go\nfunc FiniteTicker(period time.Duration, onTick func()) func()\n```\nFiniteTicker starts a goroutine to execute the given function periodically, until the returned function is called.\n\n```go\nfunc FormatJSON(v interface{}) ([]byte, error)\n```\nFormatJSON applies indent to format a JSON response.\n\n```go\nfunc HasHexPrefix(str string) bool\n```\nHasHexPrefix returns true if the string starts with 0x.\n\n```go\nfunc HashPassword(password string) (string, error)\n```\nHashPassword wraps around bcrypt.GenerateFromPassword for a friendlier API.\n\n```go\nfunc HexToBig(s string) *big.Int\n```\nHexToBig parses the given hex string or panics if it is invalid.\n\n```go\nfunc HexToUint256(s string) (*big.Int, error)\n```\nHexToUint256 returns the uint256 represented by s, or an error if it doesn't represent one.\n\n```go\nfunc ISO8601UTC(t time.Time) string\n```\nISO8601UTC formats given time to ISO8601.\n\n```go\nfunc IsEmpty(bytes []byte) bool\n```\nIsEmpty returns true if bytes contains only zero values, or has len 0.\n\n```go\nfunc IsEmptyAddress(addr common.Address) bool\n```\nIsEmptyAddress 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.\n\nSee [https://stackoverflow.com/questions/48219716/what-is-address0-in-solidity](https://stackoverflow.com/questions/48219716/what-is-address0-in-solidity) for the more info on the zero address.\n\n```go\nfunc IsFileOwnedByChainlink(fileInfo os.FileInfo) (bool, error)\n```\nIsFileOwnedByChainlink attempts to read fileInfo to verify file owner\n\n```go\nfunc IsQuoted(input []byte) bool\n```\nIsQuoted checks if the first and last characters are either \" or '.\n\n```go\nfunc JustError(_ interface{}, err error) error\n```\nJustError takes a tuple and returns the last entry, the error.\n\n```go\nfunc Keccak256(in []byte) ([]byte, error)\n```\nKeccak256 is a simplified interface for the legacy SHA3 implementation that Ethereum uses.\n\n```go\nfunc Keccak256Fixed(in []byte) [32]byte\n```\n\n```go\nfunc LeftPadBitString(input string, length int) string\n```\n\n```go\nfunc MinKey[U any, T constraints.Ordered](elems []U, key func(U) T) T\n```\nMinKey returns the minimum value of the given element array with respect to the given key function. In the event U is not a compound type (e.g a struct) an identity function can be provided.\n\n```go\nfunc MultiErrorList(err error) (int, error)\n```\nMultiErrorList returns an error which formats underlying errors as a list, or nil if err is nil.\n\n```go\nfunc MustAbiType(ts string, components []abi.ArgumentMarshaling) abi.Type\n```\n\n```go\nfunc MustHash(in string) common.Hash\n```\nMustHash returns the keccak256 hash, or panics on failure.\n\n```go\nfunc MustNewPeerID() string\n```\n\n```go\nfunc MustUnmarshalToMap(input string) map[string]interface{}\n```\nMustUnmarshalToMap performs UnmarshalToMap, panics upon failure\n\n```go\nfunc NewBytes32ID() string\n```\nNewBytes32ID returns a randomly generated UUID that conforms to Ethereum bytes32.\n\n```go\nfunc NewHash() common.Hash\n```\nNewHash return random Keccak256\n\n```go\nfunc NewRedialBackoff() backoff.Backoff\n```\nNewRedialBackoff is a standard backoff to use for redialling or reconnecting to unreachable network endpoints\n\n```go\nfunc NewSecret(n int) string\n```\nNewSecret returns a new securely random sequence of n bytes of entropy.  The result is a base64 encoded string.\n\nPanics on failed attempts to read from system's PRNG.\n\n```go\nfunc NormalizedJSON(val []byte) (string, error)\n```\nNormalizedJSON returns a JSON representation of an object that has been normalized to produce a consistent output for hashing.\n\nNOTE: 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:\n\n\tJSON does not have a requirement to respect object key ordering.\n\n```go\nfunc PadByteToHash(b byte) common.Hash\n```\nPadByteToHash returns a hash with zeros padded on the left of the given byte.\n\n```go\nfunc ParseEthereumAddress(addressString string) (common.Address, error)\n```\nParseEthereumAddress returns addressString as a go-ethereum Address, or an error if it's invalid, e.g. if EIP 55 capitalization check fails\n\n```go\nfunc PasswordFromFile(pwdFile string) (string, error)\n```\n\n```go\nfunc RandUint256() *big.Int\n```\nRandUint256 generates a random bigNum up to 2 \\*\\* 256 - 1\n\n```go\nfunc RandomAddress() common.Address\n```\n\n```go\nfunc RandomBytes32() (r [32]byte)\n```\n\n```go\nfunc RemoveHexPrefix(str string) string\n```\nRemoveHexPrefix removes the prefix (0x) of a given hex string.\n\n```go\nfunc RemoveQuotes(input []byte) []byte\n```\nRemoveQuotes removes the first and last character if they are both either \" or ', otherwise it is a noop.\n\n```go\nfunc RetryWithBackoff(ctx context.Context, fn func() (retry bool))\n```\nRetryWithBackoff retries the sleeper and backs off if not Done\n\n```go\nfunc Sha256(in string) (string, error)\n```\nSha256 returns a hexadecimal encoded string of a hashed input\n\n```go\nfunc StringToHex(in string) string\n```\nStringToHex converts a standard string to a hex encoded string.\n\n```go\nfunc ToDecimal(input interface{}) (decimal.Decimal, error)\n```\nToDecimal converts an input to a decimal\n\n```go\nfunc TooPermissive(fileMode, maxAllowedPerms os.FileMode) bool\n```\nTooPermissive checks if the file has more than the allowed permissions\n\n```go\nfunc TryParseHex(s string) (b []byte, err error)\n```\nTryParseHex parses the given hex string to bytes, it can return error if the hex string is invalid. Follows the semantic of ethereum's FromHex.\n\n```go\nfunc Uint256ToBytes(x *big.Int) (uint256 []byte, err error)\n```\nUint256ToBytes is x represented as the bytes of a uint256\n\n```go\nfunc Uint256ToBytes32(n *big.Int) []byte\n```\nUint256ToBytes32 returns the bytes32 encoding of the big int provided\n\n```go\nfunc UnmarshalToMap(input string) (map[string]interface{}, error)\n```\nUnmarshalToMap takes an input json string and returns a map\\[string]interface i.e. a raw object\n\n```go\nfunc ValidateCronSchedule(schedule string) error\n```\nValidateCronSchedule returns an error if the given schedule is invalid.\n\n```go\nfunc VerifyPasswordComplexity(password string, disallowedStrings ...string) (merr error)\n```\n\n```go\nfunc WaitGroupChan(wg *sync.WaitGroup) \u003c-chan struct{}\n```\nWaitGroupChan creates a channel that closes when the provided sync.WaitGroup is done.\n\n```go\nfunc WithCloseChan(parentCtx context.Context, chStop \u003c-chan struct{}) (ctx context.Context, cancel context.CancelFunc)\n```\nWithCloseChan 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\n\n```go\nfunc WithJitter(d time.Duration) time.Duration\n```\nWithJitter adds +/- 10% to a duration\n\n```go\nfunc WrapIfError(err *error, msg string)\n```\nWrapIfError decorates an error with the given message.  It is intended to be used with \\`defer\\` statements, like so:\n\n\tfunc SomeFunction() (err error) {\n\t    defer WrapIfError(\u0026err, \"error in SomeFunction:\")\n\n\t    ...\n\t}\n\n```go\nfunc WriteFileWithMaxPerms(path string, data []byte, perms os.FileMode) (err error)\n```\nWriteFileWithMaxPerms writes \\`data\\` to \\`path\\` and ensures that the file has permissions that are no more permissive than the given ones.\n\n## Types\n\n```go\ntype BackoffSleeper struct {\n\tbackoff.Backoff\n\t// contains filtered or unexported fields\n}\n```\nBackoffSleeper is a sleeper that backs off on subsequent attempts.\n\n```go\nfunc NewBackoffSleeper() *BackoffSleeper\n```\nNewBackoffSleeper returns a BackoffSleeper that is configured to sleep for 0 seconds initially, then backs off from 1 second minimum to 10 seconds maximum.\n\n```go\nfunc (bs *BackoffSleeper) After() time.Duration\n```\nAfter returns the duration for the next stop, and increments the backoff.\n\n```go\nfunc (bs *BackoffSleeper) Duration() time.Duration\n```\nDuration returns the current duration value.\n\n```go\nfunc (bs *BackoffSleeper) Reset()\n```\nReset resets the backoff intervals.\n\n```go\nfunc (bs *BackoffSleeper) Sleep()\n```\nSleep waits for the given duration, incrementing the back off.\n\n```go\ntype BackoffTicker struct {\n\tC chan time.Time\n\n\tsync.Mutex\n\t// contains filtered or unexported fields\n}\n```\nBackoffTicker sends ticks with periods that increase over time, over a configured range.\n\n```go\nfunc NewBackoffTicker(min, max time.Duration) BackoffTicker\n```\nNewBackoffTicker returns a new BackoffTicker for the given range.\n\n```go\nfunc (t *BackoffTicker) Bounds() (time.Duration, time.Duration)\n```\n\n```go\nfunc (t *BackoffTicker) Start() bool\n```\nStart - Starts the ticker Returns true if the ticker was not running yet\n\n```go\nfunc (t *BackoffTicker) Stop() bool\n```\nStop 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)\n\n```go\nfunc (t *BackoffTicker) Ticks() \u003c-chan time.Time\n```\nTicks returns the underlying channel.\n\n```go\ntype Big big.Int\n```\nBig stores large integers and can deserialize a variety of inputs.\n\n```go\nfunc NewBig(i *big.Int) *Big\n```\nNewBig constructs a Big from \\*big.Int.\n\n```go\nfunc NewBigI(i int64) *Big\n```\nNewBigI constructs a Big from int64.\n\n```go\nfunc (b *Big) Add(c interface{}) *Big\n```\nAdd returns the sum of b and c\n\n```go\nfunc (b *Big) Bytes() []byte\n```\nBytes returns the\n\n```go\nfunc (b *Big) Cmp(c *Big) int\n```\nCmp compares b and c as big.Ints.\n\n```go\nfunc (b *Big) Equal(c *Big) bool\n```\nEqual returns true if c is equal according to Cmp.\n\n```go\nfunc (b *Big) Hex() string\n```\nBytes returns the absolute value of b as a big-endian byte slice.\n\n```go\nfunc (b *Big) Int64() int64\n```\nInt64 casts b as an int64 type\n\n```go\nfunc (b Big) MarshalJSON() ([]byte, error)\n```\nMarshalJSON marshals this instance to base 10 number as string.\n\n```go\nfunc (b Big) MarshalText() ([]byte, error)\n```\nMarshalText marshals this instance to base 10 number as string.\n\n```go\nfunc (b *Big) Mod(c interface{}) *Big\n```\nSub returns b % c\n\n```go\nfunc (b *Big) Scan(value interface{}) error\n```\nScan reads the database value and returns an instance.\n\n```go\nfunc (b *Big) String() string\n```\nString returns the base 10 encoding of b.\n\n```go\nfunc (b *Big) Sub(c interface{}) *Big\n```\nSub returns the differencs between b and c\n\n```go\nfunc (b *Big) ToInt() *big.Int\n```\nToInt converts b to a big.Int.\n\n```go\nfunc (b *Big) UnmarshalJSON(input []byte) error\n```\nUnmarshalJSON implements encoding.JSONUnmarshaler.\n\n```go\nfunc (b *Big) UnmarshalText(input []byte) error\n```\nUnmarshalText implements encoding.TextUnmarshaler.\n\n```go\nfunc (b Big) Value() (driver.Value, error)\n```\nValue returns this instance serialized for database storage.\n\n```go\ntype BigFloat big.Float\n```\nBigFloat accepts both string and float JSON values.\n\n```go\nfunc (b BigFloat) MarshalJSON() ([]byte, error)\n```\nMarshalJSON implements the json.Marshaler interface.\n\n```go\nfunc (b *BigFloat) UnmarshalJSON(buf []byte) error\n```\nUnmarshalJSON implements the json.Unmarshal interface.\n\n```go\nfunc (b *BigFloat) Value() *big.Float\n```\nValue returns the big.Float value.\n\n```go\ntype BoundedPriorityQueue[T any] struct {\n\t// contains filtered or unexported fields\n}\n```\nBoundedPriorityQueue stores a series of BoundedQueues with associated priorities and capacities\n\n```go\nfunc NewBoundedPriorityQueue[T any](capacities map[uint]int) *BoundedPriorityQueue[T]\n```\nNewBoundedPriorityQueue creates a new BoundedPriorityQueue\n\n```go\nfunc (q *BoundedPriorityQueue[T]) Add(priority uint, x T)\n```\nAdd pushes an item into a subque within a BoundedPriorityQueue\n\n```go\nfunc (q *BoundedPriorityQueue[T]) Empty() bool\n```\nEmpty checks the BoundedPriorityQueue if all subqueues are empty\n\n```go\nfunc (q *BoundedPriorityQueue[T]) Take() (t T)\n```\nTake takes from the BoundedPriorityQueue's subque\n\n```go\ntype BoundedQueue[T any] struct {\n\t// contains filtered or unexported fields\n}\n```\nBoundedQueue is a FIFO queue that discards older items when it reaches its capacity.\n\n```go\nfunc NewBoundedQueue[T any](capacity int) *BoundedQueue[T]\n```\nNewBoundedQueue creates a new BoundedQueue instance\n\n```go\nfunc (q *BoundedQueue[T]) Add(x T)\n```\nAdd appends items to a BoundedQueue\n\n```go\nfunc (q *BoundedQueue[T]) Empty() bool\n```\nEmpty check is a BoundedQueue is empty\n\n```go\nfunc (q *BoundedQueue[T]) Full() bool\n```\nFull checks if a BoundedQueue is over capacity.\n\n```go\nfunc (q *BoundedQueue[T]) Take() (t T)\n```\nTake pulls the first item from the array and removes it\n\n```go\ntype CronTicker struct {\n\t*cron.Cron\n\t// contains filtered or unexported fields\n}\n```\nCronTicker is like a time.Ticker but for a cron schedule.\n\n```go\nfunc NewCronTicker(schedule string) (CronTicker, error)\n```\nNewCronTicker returns a new CrontTicker for the given schedule.\n\n```go\nfunc (t *CronTicker) Start() bool\n```\nStart - returns true if the CronTicker was actually started, false otherwise\n\n```go\nfunc (t *CronTicker) Stop() bool\n```\nStop - returns true if the CronTicker was actually stopped, false otherwise\n\n```go\nfunc (t *CronTicker) Ticks() \u003c-chan time.Time\n```\nTicks returns the underlying chanel.\n\n```go\ntype DeferableWriteCloser struct {\n\tio.WriteCloser\n\t// contains filtered or unexported fields\n}\n```\nDeferableWriteCloser is to be used in leiu of defer'ing Close on an [io.WriteCloser](/io#WriteCloser) (// For more background see [https://www.joeshaw.org/dont-defer-close-on-writable-files/](https://www.joeshaw.org/dont-defer-close-on-writable-files/)) Callers should \\*both\\* explicitly call Close and check for errors when done with the underlying writerclose \\*and\\* defer the Close() to handle returns before the explicit close\n\nFor example rather than\n\n\timport \"os\"\n\tf, err := os.Create(\"./foo\")\n\tif err != nil { return err}\n\tdefer f.Close()\n\treturn f.Write([]bytes(\"hi\"))\n\ndo\n\n\timport \"os\"\n\tf, err := os.Create(\"./foo\")\n\tif err != nil {return nil}\n\twc := NewDeferableWriteCloser(f)\n\tdefer wc.Close()\n\terr = wc.Write([]bytes(\"hi\"))\n\tif err != nil {return err}\n\treturn wc.Close()\n\n```go\nfunc NewDeferableWriteCloser(wc io.WriteCloser) *DeferableWriteCloser\n```\nNewDeferableWriteCloser creates a deferable writercloser. Callers should explicit call and defer Close. See DeferabelWriterCloser for details.\n\n```go\nfunc (wc *DeferableWriteCloser) Close() error\n```\nClose closes the WriterCloser. The underlying Closer is Closed exactly once and resulting error is cached. Should be called explicitly AND defered Thread safe\n\n```go\ntype DependentAwaiter interface {\n\tAwaitDependents() \u003c-chan struct{}\n\tAddDependents(n int)\n\tDependentReady()\n}\n```\nDependentAwaiter contains Dependent funcs\n\n```go\nfunc NewDependentAwaiter() DependentAwaiter\n```\nNewDependentAwaiter creates a new DependentAwaiter\n\n```go\ntype DiskStatsProvider interface {\n\tAvailableSpace(path string) (FileSize, error)\n}\n```\nDiskStatsProvider describes the abstraction to the \\`shirou/gopsutil/v3\\` for mocking purposes\n\n```go\nfunc NewDiskStatsProvider() DiskStatsProvider\n```\nNewDiskStatsProvider returns a new \\`DiskStatsProvider\\` instance\n\n```go\ntype FileSize uint64\n```\nFileSize repesents a file size in bytes.\n\n```go\nfunc (s FileSize) MarshalText() ([]byte, error)\n```\nMarshalText encodes s as a human readable string.\n\n```go\nfunc (s FileSize) String() string\n```\n\n```go\nfunc (s *FileSize) UnmarshalText(bs []byte) error\n```\nUnmarshalText parses a file size from bs in to s.\n\n```go\ntype KeyedMutex struct {\n\t// contains filtered or unexported fields\n}\n```\nKeyedMutex allows to lock based on particular values\n\n```go\nfunc (m *KeyedMutex) LockInt64(key int64) func()\n```\nLockInt64 locks the value for read/write\n\n```go\ntype LazyLoad[T any] struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewLazyLoad[T any](f func() (T, error)) *LazyLoad[T]\n```\n\n```go\nfunc (l *LazyLoad[T]) Get() (out T, err error)\n```\n\n```go\nfunc (l *LazyLoad[T]) Reset()\n```\n\n```go\ntype Mailbox[T any] struct {\n\t// contains filtered or unexported fields\n}\n```\nMailbox contains a notify channel, a mutual exclusive lock, a queue of interfaces, and a queue capacity.\n\n```go\nfunc NewHighCapacityMailbox[T any]() *Mailbox[T]\n```\nNewHighCapacityMailbox create a new mailbox with a capacity that is better able to handle e.g. large log replays.\n\n```go\nfunc NewMailbox[T any](capacity uint64) *Mailbox[T]\n```\nNewMailbox creates a new mailbox instance. If name is non-empty, it must be unique and calling Start will launch prometheus metric monitor that periodically reports mailbox load until Close() is called.\n\n```go\nfunc NewSingleMailbox[T any]() *Mailbox[T]\n```\nNewSingleMailbox returns a new Mailbox with capacity one.\n\n```go\nfunc (m *Mailbox[T]) Close() error\n```\n\n```go\nfunc (m *Mailbox[T]) Deliver(x T) (wasOverCapacity bool)\n```\nDeliver appends to the queue and returns true if the queue was full, causing a message to be dropped.\n\n```go\nfunc (m *Mailbox[T]) Notify() \u003c-chan struct{}\n```\nNotify returns the contents of the notify channel\n\n```go\nfunc (m *Mailbox[T]) Retrieve() (t T, ok bool)\n```\nRetrieve fetches one element from the queue.\n\n```go\nfunc (m *Mailbox[T]) RetrieveAll() []T\n```\nRetrieveAll fetches all elements from the queue.\n\n```go\nfunc (m *Mailbox[T]) RetrieveLatestAndClear() (t T)\n```\nRetrieveLatestAndClear fetch the latest value (or nil), and clears the rest of the queue (if any).\n\n```go\ntype MailboxMonitor struct {\n\tStartStopOnce\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewMailboxMonitor(appID string) *MailboxMonitor\n```\n\n```go\nfunc (m *MailboxMonitor) Close() error\n```\n\n```go\nfunc (m *MailboxMonitor) HealthReport() map[string]error\n```\n\n```go\nfunc (m *MailboxMonitor) Monitor(mb mailbox, name ...string)\n```\n\n```go\nfunc (m *MailboxMonitor) Name() string\n```\n\n```go\nfunc (m *MailboxMonitor) Start(context.Context) error\n```\n\n```go\ntype PausableTicker struct {\n\t// contains filtered or unexported fields\n}\n```\nPausableTicker stores a ticker with a duration\n\n```go\nfunc NewPausableTicker(duration time.Duration) PausableTicker\n```\nNewPausableTicker creates a new PausableTicker\n\n```go\nfunc (t *PausableTicker) Destroy()\n```\nDestroy pauses the PausibleTicker\n\n```go\nfunc (t *PausableTicker) Pause()\n```\nPause pauses a PausableTicker\n\n```go\nfunc (t *PausableTicker) Resume()\n```\nResume resumes a Ticker using a PausibleTicker's duration\n\n```go\nfunc (t *PausableTicker) Ticks() \u003c-chan time.Time\n```\nTicks retrieves the ticks from a PausableTicker\n\n```go\ntype ResettableTimer struct {\n\t// contains filtered or unexported fields\n}\n```\nResettableTimer stores a timer\n\n```go\nfunc NewResettableTimer() ResettableTimer\n```\nNewResettableTimer creates a new ResettableTimer\n\n```go\nfunc (t *ResettableTimer) Reset(duration time.Duration)\n```\nReset stops a ResettableTimer and resets it with a new duration\n\n```go\nfunc (t *ResettableTimer) Stop()\n```\nStop stops a ResettableTimer\n\n```go\nfunc (t *ResettableTimer) Ticks() \u003c-chan time.Time\n```\nTicks retrieves the ticks from a ResettableTimer\n\n```go\ntype ScryptConfigReader interface {\n\tInsecureFastScrypt() bool\n}\n```\nScryptConfigReader can check for an insecure, fast flag\n\n```go\ntype ScryptParams struct{ N, P int }\n```\nScryptParams represents two integers, N and P.\n\n```go\nfunc GetScryptParams(config ScryptConfigReader) ScryptParams\n```\nGetScryptParams fetches ScryptParams from a ScryptConfigReader\n\n```go\ntype Sleeper interface {\n\tReset()\n\tSleep()\n\tAfter() time.Duration\n\tDuration() time.Duration\n}\n```\nSleeper interface is used for tasks that need to be done on some interval, excluding Cron, like reconnecting.\n\n```go\ntype SleeperTask interface {\n\tStop() error\n\tWakeUp()\n\tWakeUpIfStarted()\n}\n```\nSleeperTask represents a task that waits in the background to process some work.\n\n```go\nfunc NewSleeperTask(worker Worker) SleeperTask\n```\nNewSleeperTask takes a worker and returns a SleeperTask.\n\nSleeperTask 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.\n\n```go\ntype StartStopOnce struct {\n\tsync.RWMutex // lock is held during startup/shutdown, RLock is held while executing functions dependent on a particular state\n\t// contains filtered or unexported fields\n}\n```\nStartStopOnce contains a StartStopOnceState integer\n\n```go\nfunc (once *StartStopOnce) Healthy() error\n```\nHealthy returns ErrNotStarted if the state is not started. Override this per-service with more specific implementations.\n\n```go\nfunc (once *StartStopOnce) IfNotStopped(f func()) (ok bool)\n```\nIfNotStopped runs the func and returns true if in any state other than Stopped\n\n```go\nfunc (once *StartStopOnce) IfStarted(f func()) (ok bool)\n```\nIfStarted runs the func and returns true only if started, otherwise returns false\n\n```go\nfunc (once *StartStopOnce) Ready() error\n```\nReady returns ErrNotStarted if the state is not started.\n\n```go\nfunc (once *StartStopOnce) StartOnce(name string, fn func() error) error\n```\nStartOnce sets the state to Started\n\n```go\nfunc (once *StartStopOnce) State() StartStopOnceState\n```\nState retrieves the current state\n\n```go\nfunc (once *StartStopOnce) StopOnce(name string, fn func() error) error\n```\nStopOnce sets the state to Stopped\n\n```go\ntype StartStopOnceState int32\n```\nStartStopOnceState holds the state for StartStopOnce\n\n```go\nconst (\n\tStartStopOnce_Unstarted StartStopOnceState = iota\n\tStartStopOnce_Started\n\tStartStopOnce_Starting\n\tStartStopOnce_StartFailed\n\tStartStopOnce_Stopping\n\tStartStopOnce_Stopped\n\tStartStopOnce_StopFailed\n)\n```\nnolint\n\n```go\nfunc (s StartStopOnceState) String() string\n```\n\n```go\ntype TickerBase interface {\n\tResume()\n\tPause()\n\tDestroy()\n\tTicks() \u003c-chan time.Time\n}\n```\nTickerBase is an interface for pausable tickers.\n\n```go\ntype Worker interface {\n\tWork()\n\tName() string\n}\n```\nWorker is a simple interface that represents some work to do repeatedly\n\n```go\nfunc SleeperFuncTask(work func(), name string) Worker\n```\nSleeperFuncTask returns a Worker to execute the given work function.\n\n","path":"github.com/GoPlugin/pluginV2/core/utils","name":"utils","synopsis":"Package utils is used for common functions and tools used across the codebase.","isRedistributable":true}
