Documentation
¶
Overview ¶
Package tools 工具箱
Package tools 字节转化
Index ¶
- func Args(params ...interface{}) []interface{}
- func AutoLock(mu *sync.Mutex, fun func())
- func AutoRLock(mu *sync.RWMutex, fun func())
- func AutoWLock(mu *sync.RWMutex, fun func())
- func BoolToBytes(v bool) []byte
- func BytesToBool(buf []byte) bool
- func BytesToFloat32(bytes []byte) float32
- func BytesToFloat64(bytes []byte) float64
- func BytesToInt32(buf []byte) int32
- func BytesToInt64(buf []byte) int64
- func BytesToMap(bytes []byte) (map[string]any, error)
- func Cast(condition bool, trueFun, falseFun func())
- func Catch(desc string, x interface{}) error
- func DefaultVal[T any](vars []T) T
- func Float32ToBytes(float float32) []byte
- func Float64ToBytes(float float64) []byte
- func FromBase34(s string) (uint64, error)
- func FromBase62(str string) int64
- func FuncFullName(fun interface{}, seps ...rune) string
- func FuncFullNameRef(valFun reflect.Value, seps ...rune) string
- func FuncName(fun interface{}) string
- func Int32ToBytes(i int32) []byte
- func Int64ToBytes(i int64) []byte
- func JSONToMsgPack(jsonStr string) ([]byte, error)
- func Lock(mu *sync.Mutex) *sync.Mutex
- func MapToBytes(jmap map[string]any) ([]byte, error)
- func MsgPackToJSON(msgpackData []byte) (string, error)
- func RLock(mu *sync.RWMutex) *sync.RWMutex
- func RUnLock(rMutex *sync.RWMutex)
- func StructName(obj interface{}) string
- func Tern[T bool, U any](isTrue T, ifValue U, elseValue U) U
- func ToBase34(d uint64) string
- func ToBase62(number int64) string
- func UnLock(lockFun *sync.Mutex)
- func WLock(mu *sync.RWMutex) *sync.RWMutex
- func WUnLock(wMutex *sync.RWMutex)
- type ID
- type ILocker
- type IRWLocker
- type InvalidLocker
- type Locker
- type Map
- type Queue
- type RWLocker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromBase62 ¶ added in v1.1.7
FromBase62 解码base62字符串为整数(0表示非法字符或溢出)
func FuncFullName ¶ added in v1.2.0
func FuncFullNameRef ¶ added in v1.2.0
func JSONToMsgPack ¶ added in v1.1.7
JSON → MsgPack
func MsgPackToJSON ¶ added in v1.1.7
MsgPack → JSON
Types ¶
type ID ¶
type ID uint64
An ID is a unique, uniformly distributed 64-bit ID.
func GenerateID ¶
func GenerateID() ID
GenerateID returns a randomly-generated 64-bit ID. This function is thread-safe. IDs are produced by consuming an AES-CTR-128 keystream in 64-bit chunks. The AES key is randomly generated on initialization, as is the counter's initial state. On machines with AES-NI support, ID generation takes ~30ns and generates no garbage.
func (ID) MarshalJSON ¶
MarshalJSON encodes the ID as a hex string.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON decodes the given data as either a hexadecimal string or JSON integer.
type ILocker ¶ added in v1.2.0
type ILocker interface {
// 主锁
Lock() interface{}
UnLock(i interface{})
}
普通锁
type IRWLocker ¶ added in v1.2.0
type IRWLocker interface {
// 写锁
ILocker
// 读锁
RLock() interface{}
RUnLock(i interface{})
}
读写锁
type InvalidLocker ¶ added in v1.2.0
type InvalidLocker struct {
}
InvalidLocker is a fake locker
func (InvalidLocker) Lock ¶ added in v1.2.0
func (l InvalidLocker) Lock() interface{}
Lock does nothing
func (InvalidLocker) RLock ¶ added in v1.2.0
func (l InvalidLocker) RLock() interface{}
RLock does nothing
func (InvalidLocker) RUnLock ¶ added in v1.2.0
func (l InvalidLocker) RUnLock(i interface{})
RUnlock does nothing
func (InvalidLocker) UnLock ¶ added in v1.2.0
func (l InvalidLocker) UnLock(i interface{})
Unlock does nothing
type Locker ¶ added in v1.2.0
type Locker struct {
// contains filtered or unexported fields
}
==================== Locker
type Map ¶ added in v1.2.0
type Map[K comparable] struct { // contains filtered or unexported fields }
Map is a map with lock
func NewSafeMap ¶ added in v1.1.7
func NewSafeMap[K comparable]() *Map[K]
NewSafeMap return new safemap
func (*Map[K]) Delete ¶ added in v1.2.0
func (m *Map[K]) Delete(k K)
Delete the given key and value.
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue represents a single instance of the queue data structure.
func (*Queue[T]) Get ¶
Get returns the element at index i in the queue. If the index is invalid, the call will panic. This method accepts both positive and negative index values. Index 0 refers to the first element, and index -1 refers to the last.