util
v9.24.1
Documentation
pkg.go.dev ↗Functions
Atoi
func Atoi(b []byte) (int, error)
BytesToString
func BytesToString(b []byte) string
BytesToString converts byte slice to string.
MustParseFloat
func MustParseFloat(s string) float64
MustParseFloat is like ParseFloat but panics on parse errors.
ParseFloat
func ParseFloat(b []byte, bitSize int) (float64, error)
ParseInt
func ParseInt(b []byte, base int, bitSize int) (int64, error)
ParseStringToFloat
func ParseStringToFloat(s string) (float64, error)
ParseFloat parses a Redis RESP3 float reply into a Go float64, handling "inf", "-inf", "nan" per Redis conventions.
ParseUint
func ParseUint(b []byte, base int, bitSize int) (uint64, error)
SafeIntToInt32
func SafeIntToInt32(value int, fieldName string) (int32, error)
SafeIntToInt32 safely converts an int to int32, returning an error if overflow would occur.
StringToBytes
func StringToBytes(s string) []byte
StringToBytes converts string to byte slice.
ToPtr
func ToPtr[T any](v T) *T
Types
AtomicMax
type AtomicMax struct {
// contains filtered or unexported fields
}
AtomicMax is a thread-safe max container
- hasValue indicator true if a value was equal to or greater than threshold
- optional threshold for minimum accepted max value
- if threshold is not used, initialization-free
- —
- wait-free CompareAndSwap mechanic
NewAtomicMax
func NewAtomicMax() (atomicMax *AtomicMax)
NewAtomicMax returns a thread-safe max container
- if threshold is not used, AtomicMax is initialization-free
AtomicMax.Max
func (m *AtomicMax) Max() (value float64, hasValue bool)
Max returns current max and value-present flag
- hasValue true indicates that value reflects a Value invocation
- hasValue false: value is zero-value
- Thread-safe
AtomicMax.Max1
func (m *AtomicMax) Max1() (value float64)
Max1 returns current maximum whether zero-value or set by Value
- threshold is ignored
- Thread-safe
AtomicMax.Value
func (m *AtomicMax) Value(value float64) (isNewMax bool)
Value updates the container with a possible max value
- isNewMax is true if:
- — value is equal to or greater than any threshold and
- — invocation recorded the first 0 or
- — a new max
- upon return, Max and Max1 are guaranteed to reflect the invocation
- the return order of concurrent Value invocations is not guaranteed
- Thread-safe
AtomicMin
type AtomicMin struct {
// contains filtered or unexported fields
}
AtomicMin is a thread-safe Min container
- hasValue indicator true if a value was equal to or greater than threshold
- optional threshold for minimum accepted Min value
- —
- wait-free CompareAndSwap mechanic
NewAtomicMin
func NewAtomicMin() (atomicMin *AtomicMin)
NewAtomicMin returns a thread-safe Min container
- if threshold is not used, AtomicMin is initialization-free
AtomicMin.Min
func (m *AtomicMin) Min() (value float64, hasValue bool)
Min returns current min and value-present flag
- hasValue true indicates that value reflects a Value invocation
- hasValue false: value is zero-value
- Thread-safe
AtomicMin.Min1
func (m *AtomicMin) Min1() (value float64)
Min1 returns current Minimum whether zero-value or set by Value
- threshold is ignored
- Thread-safe
AtomicMin.Value
func (m *AtomicMin) Value(value float64) (isNewMin bool)
Value updates the container with a possible Min value
- isNewMin is true if:
- — value is equal to or greater than any threshold and
- — invocation recorded the first 0 or
- — a new Min
- upon return, Min and Min1 are guaranteed to reflect the invocation
- the return order of concurrent Value invocations is not guaranteed
- Thread-safe