Documentation ¶
Index ¶
- Constants
- func ChangeToCoin(change int64) float64
- func ChangeToString(change int64) string
- func ChangeToStringWithTrailingZeros(change int64) string
- func CoinToChange(coin float64) int64
- func CompressBuffer(s []byte) ([]byte, error)
- func Contains[T comparable](slice []T, item T) bool
- func DecompressBuffer(s []byte) ([]byte, error)
- func Equal[T comparable](a, b []T) bool
- func Extend[T any](s *[]T, n int)
- func IS2OP(x *big.Int, xLen int) []byte
- func Int16ToSlice(n int16) []byte
- func Int32ToSlice(n int32) []byte
- func Int64ToSlice(n int64) []byte
- func IsAbsPath(p string) bool
- func IsDirEmpty(name string) bool
- func IsDirNotExistsOrEmpty(name string) bool
- func IsFlagSet[T constraints.Integer](flags, mask T) bool
- func IsSubset[T comparable](parentSet, subSet []T) bool
- func IsValidDirPath(fp string) bool
- func LogScale(val int) int
- func MakeAbs(p string) string
- func Max[T constraints.Integer](a, b T) T
- func Merge[T any](slices ...[]T) []T
- func Min[T constraints.Integer](a, b T) T
- func Mkdir(dir string) error
- func Now() time.Time
- func OS2IP(os []byte) *big.Int
- func PathExists(p string) bool
- func RandInt16(max int16) int16
- func RandInt32(max int32) int32
- func RandInt64(max int64) int64
- func RandUint16(max uint32) uint16
- func RandUint32(max uint32) uint32
- func RandUint64(max uint64) uint64
- func ReadFile(filename string) ([]byte, error)
- func RemoveFirstOccurrenceOf[T comparable](s []T, e T) ([]T, bool)
- func Reverse[S ~[]E, E any](s S)
- func RoundNow(sec int) time.Time
- func SafeCmp(s1, s2 []byte) bool
- func SetFlag[T constraints.Integer](flags, mask T) T
- func SliceToInt16(bs []byte) int16
- func SliceToInt32(bs []byte) int32
- func SliceToInt64(bs []byte) int64
- func SliceToUint16(bs []byte) uint16
- func SliceToUint32(bs []byte) uint32
- func SliceToUint64(bs []byte) uint64
- func StringToBytes(s string) []byte
- func StringToChange(amount string) (int64, error)
- func Subtracts(slice1, slice2 []int32) []int32
- func TempDirPath() string
- func TempFilePath() string
- func Trim[T any](s []T, newLength int) []T
- func Uint16ToSlice(n uint16) []byte
- func Uint32ToSlice(n uint32) []byte
- func Uint64ToSlice(n uint64) []byte
- func UnsetFlag[T constraints.Integer](flags, mask T) T
- func WriteFile(filename string, data []byte) error
- type FixedReader
- type FixedWriter
Constants ¶
const ( MaxUint16 = ^uint16(0) MinUint16 = 0 MaxInt16 = int16(MaxUint16 >> 1) MinInt16 = -MaxInt16 - 1 )
const ( MaxUint32 = ^uint32(0) MinUint32 = 0 MaxInt32 = int32(MaxUint32 >> 1) MinInt32 = -MaxInt32 - 1 )
const ( MaxUint64 = ^uint64(0) MinUint64 = 0 MaxInt64 = int64(MaxUint64 >> 1) MinInt64 = -MaxInt64 - 1 )
Variables ¶
This section is empty.
Functions ¶
func ChangeToCoin ¶
ChangeToCoin converts a change value to its corresponding coin amount. Example: ChangeToCoin(2750000000) returns 2.75.
func ChangeToString ¶
ChangeToString converts a change value to its string representation. Example: ChangeToString(2750000000) returns "2.75".
func ChangeToStringWithTrailingZeros ¶ added in v0.11.0
ChangeToStringWithTrailingZeros converts a change value to its string representation with trailing zeros. The returned string will have up to 9 decimal places. Example: ChangeToStringWithTrailingZeros(2750000000) returns "2.750000000".
func CoinToChange ¶
CoinToChange converts a coin amount to its corresponding change value. Example: CoinToChange(2.75) returns 2750000000.
func CompressBuffer ¶
func Contains ¶
func Contains[T comparable](slice []T, item T) bool
Contains checks whether the given slice has a specific item.
func DecompressBuffer ¶
func Equal ¶
func Equal[T comparable](a, b []T) bool
Equal tells whether a and b contain the same elements. A nil argument is equivalent to an empty slice.
func Extend ¶ added in v0.15.0
Extend extends the slice 's' to length 'n' by appending zero-valued elements.
func IS2OP ¶
I2OSP converts a nonnegative integer to an octet string of a specified length. https://datatracker.ietf.org/doc/html/rfc8017#section-4.1
func Int16ToSlice ¶
func Int32ToSlice ¶
func Int64ToSlice ¶
func IsDirEmpty ¶
func IsDirNotExistsOrEmpty ¶
func IsFlagSet ¶
func IsFlagSet[T constraints.Integer](flags, mask T) bool
IsFlagSet checks if the mask is set for the given flags.
func IsSubset ¶ added in v0.15.0
func IsSubset[T comparable](parentSet, subSet []T) bool
IsSubset checks if subSet is a subset of parentSet. It returns true if all elements of subSet are in parentSet.
func IsValidDirPath ¶
func LogScale ¶ added in v0.17.0
LogScale computes 2^⌈log₂(val)⌉, where ⌈x⌉ represents the ceiling of x. For more information, refer to: https://en.wikipedia.org/wiki/Logarithmic_scale
func Max ¶ added in v0.15.0
func Max[T constraints.Integer](a, b T) T
Max returns the biggest of two integer numbers.
func Merge ¶ added in v0.10.0
func Merge[T any](slices ...[]T) []T
Merge accepts multiple slices and returns a single merged slice.
func Min ¶ added in v0.15.0
func Min[T constraints.Integer](a, b T) T
Min returns the smallest of two integer numbers.
func OS2IP ¶
OS2IP converts an octet string to a nonnegative integer. OS2IP: https://datatracker.ietf.org/doc/html/rfc8017#section-4.2
func PathExists ¶
func RandInt16 ¶
RandInt16 returns a random int16 in between 0 and max. If max set to zero or negative, the max will set to MaxInt16.
func RandInt32 ¶
RandInt32 returns a random int32 in between 0 and max. If max set to zero or negative, the max will set to MaxInt32.
func RandInt64 ¶
RandInt64 returns a random int64 in between 0 and max. If max set to zero or negative, the max will set to MaxInt64.
func RandUint16 ¶
RandUint16 returns a random uint16 in between 0 and max. If max set to zero or negative, the max will set to MaxUint16.
func RandUint32 ¶
RandUint32 returns a random uint32 in between 0 and max. If max set to zero or negative, the max will set to MaxUint32.
func RandUint64 ¶
RandUint64 returns a random uint64 in between 0 and max. If max set to zero or negative, the max will set to MaxUint64.
func RemoveFirstOccurrenceOf ¶ added in v0.15.0
func RemoveFirstOccurrenceOf[T comparable](s []T, e T) ([]T, bool)
RemoveFirstOccurrenceOf removes the first occurrence of element e from slice s. It returns the modified slice and a boolean indicating whether an element was removed.
func Reverse ¶
func Reverse[S ~[]E, E any](s S)
Reverse replace the contents of a slice with the same elements but in reverse order.
func RoundNow ¶
RoundNow returns the result of rounding sec to the current time in UTC. The rounding behavior is rounding down.
func SafeCmp ¶
SafeCmp compares two slices with constant time. Note that we are using the subtle.ConstantTimeCompare() function for this to help prevent timing attacks.
func SetFlag ¶
func SetFlag[T constraints.Integer](flags, mask T) T
SetFlag applies mask to the flags.
func SliceToInt16 ¶
func SliceToInt32 ¶
func SliceToInt64 ¶
func SliceToUint16 ¶
func SliceToUint32 ¶
func SliceToUint64 ¶
func StringToBytes ¶ added in v0.15.0
StringToBytes converts a string to a slice of bytes.
func StringToChange ¶
StringToChange converts a string representation of a coin amount to its corresponding change value. It returns the change value as an int64 and an error if the string cannot be parsed. Example: StringToChange("2.75") returns 2750000000, nil.
func Subtracts ¶
Subtracts subtracts slice2 from slice1 in order. Examples:
[1,2,3,4] - [1,2] = [3,4] [1,2,3,4] - [2,4] = [1,3] [1,2,3,4] - [4,2] = [1,3] [1,2,3,4] - [4,5] = [1,2,3]
.
func TempDirPath ¶
func TempDirPath() string
func TempFilePath ¶
func TempFilePath() string
func Uint16ToSlice ¶
func Uint32ToSlice ¶
func Uint64ToSlice ¶
func UnsetFlag ¶
func UnsetFlag[T constraints.Integer](flags, mask T) T
UnsetFlag removes mask from the flags.
Types ¶
type FixedReader ¶
type FixedReader struct {
// contains filtered or unexported fields
}
fixedReader implements the io.Reader interface and intentionally allows testing of error paths by forcing short reads.
func NewFixedReader ¶
func NewFixedReader(max int, buf []byte) *FixedReader
newFixedReader returns a new io.Reader that will error once more bytes than the specified max have been read.
func (*FixedReader) Read ¶
func (fr *FixedReader) Read(p []byte) (int, error)
Read reads the next len(p) bytes from the fixed reader. When the number of bytes read would exceed the maximum number of allowed bytes to be read from the fixed writer, an error is returned.
This satisfies the io.Reader interface.
type FixedWriter ¶
type FixedWriter struct {
// contains filtered or unexported fields
}
fixedWriter implements the io.Writer interface and intentionally allows testing of error paths by forcing short writes.
func NewFixedWriter ¶
func NewFixedWriter(max int) *FixedWriter
newFixedWriter returns a new io.Writer that will error once more bytes than the specified max have been written.
func (*FixedWriter) Bytes ¶
func (w *FixedWriter) Bytes() []byte
Bytes returns the bytes already written to the fixed writer.
func (*FixedWriter) Write ¶
func (w *FixedWriter) Write(p []byte) (int, error)
Write writes the contents of p to w. When the contents of p would cause the writer to exceed the maximum allowed size of the fixed writer, io.ErrShortWrite is returned and the writer is left unchanged.
This satisfies the io.Writer interface.