Documentation
¶
Overview ¶
* @Author: kamalyes 501893067@qq.com * @Date: 2025-01-05 15:08:55 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-01-09 15:07:15 * @FilePath: \go-toolbox\pkg\syncx\atomic.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-01-05 15:27:15 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-01-05 15:27:15 * @FilePath: \go-toolbox\pkg\syncx\clone.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2024-12-13 13:05:03 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-01-09 13:23:29 * @FilePath: \go-toolbox\pkg\syncx\lock.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-01-15 11:55:06 * @FilePath: \go-toolbox\pkg\syncx\map.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2024-10-24 11:25:16 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-01-17 13:03:15 * @FilePath: \go-toolbox\pkg\syncx\pool.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2024-11-09 01:15:05 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-11 13:08:58 * @FilePath: \go-toolbox\pkg\syncx\set.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-01-08 13:55:22 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-01-09 18:25:16 * @FilePath: \go-toolbox\pkg\syncx\wg.go * @Description: 自定义的 WaitGroup 结构体,封装了 sync.WaitGroup,用于管理并发操作的等待 * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
Index ¶
- func CopyMeta(src, dst map[string]string)
- func DeepCopy(dst, src interface{}) error
- func MetaMapToString(meta map[string]string) string
- func MetaStringToMap(meta string) map[string]string
- func WithLock(lock Locker, operation func())
- func WithLockReturn[T any](lock Locker, operation func() (T, error)) (T, error)
- func WithLockReturnValue[T any](lock Locker, operation func() T) T
- func WithRLock(lock RLocker, operation func())
- func WithRLockReturn[T any](lock RLocker, operation func() (T, error)) (T, error)
- func WithRLockReturnValue[T any](lock RLocker, operation func() T) T
- type Bool
- type Int32
- type Int64
- type LimitedPool
- type Locker
- type Map
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) Clone() *Map[K, V]
- func (m *Map[K, V]) CompareAndDelete(key K, value V) bool
- func (m *Map[K, V]) CompareAndSwap(key K, old, new V) bool
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Equals(key K, value V, cmpFunc func(existing V) bool) bool
- func (m *Map[K, V]) Keys() []K
- func (m *Map[K, V]) Load(key K) (V, bool)
- func (m *Map[K, V]) LoadAndDelete(key K) (V, bool)
- func (m *Map[K, V]) LoadOrStore(key K, new V) (V, bool)
- func (m *Map[K, V]) Range(run func(key K, value V) bool)
- func (m *Map[K, V]) Size() int
- func (m *Map[K, V]) Store(key K, value V)
- func (m *Map[K, V]) Swap(key K, value V) (pre V, ok bool)
- func (m *Map[K, V]) Values() []V
- type RLocker
- type Set
- func (s *Set[K]) Add(key K)
- func (s *Set[K]) AddAll(keys ...K)
- func (s *Set[K]) Clear()
- func (s *Set[K]) Delete(key K)
- func (s *Set[K]) DeleteAll(keys ...K)
- func (s *Set[K]) Elements() []K
- func (s *Set[K]) Has(key K) bool
- func (s *Set[K]) HasAll(keys ...K) (existing []K, all bool)
- func (s *Set[K]) IsEmpty() bool
- func (s *Set[K]) Size() int
- type Uint32
- type Uint64
- type Uintptr
- type WaitGroup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeepCopy ¶ added in v0.11.27
func DeepCopy(dst, src interface{}) error
DeepCopy 复制源值到目标值
@params dst: 目标值的指针,表示要将源值复制到的位置。必须是一个指向某种类型的指针。 @params src: 源值的指针,表示要复制的原始数据。也必须是一个指向某种类型的指针。
@return:
如果成功,返回 nil;如果源值为 nil,返回一个错误。
func MetaMapToString ¶
MetaMapToString 将 map 转换为 meta 字符串
func MetaStringToMap ¶
MetaStringToMap 将 meta 字符串转换为键值对的 map
func WithLock ¶ added in v0.11.20
func WithLock(lock Locker, operation func())
WithLock 是一个通用的函数,用于在给定的锁上执行操作
func WithLockReturn ¶ added in v0.11.23
WithLockReturn 是一个支持返回值的函数,用于在给定的锁上执行操作
func WithLockReturnValue ¶ added in v0.11.29
WithLockReturnValue 是一个支持返回值的函数,用于在给定的锁上执行操作,不返回错误
func WithRLock ¶ added in v0.11.28
func WithRLock(lock RLocker, operation func())
WithRLock 是一个用于在给定的读锁上执行操作的函数
func WithRLockReturn ¶ added in v0.11.28
WithRLockReturn 是一个支持返回值的函数,用于在给定的读锁上执行操作
func WithRLockReturnValue ¶ added in v0.11.29
WithRLockReturnValue 是一个支持返回值的函数,用于在给定的读锁上执行操作,不返回错误
Types ¶
type Bool ¶ added in v0.11.29
type Bool struct {
// contains filtered or unexported fields
}
Bool 类型,使用 atomic.Int32 来表示布尔值
type Int32 ¶ added in v0.11.29
type Int32 struct {
// contains filtered or unexported fields
}
Int32 类型,使用 atomic.Int32 来表示整数
type Int64 ¶ added in v0.11.29
type Int64 struct {
// contains filtered or unexported fields
}
Int64 类型,使用 atomic.Int64 来表示整数
type LimitedPool ¶ added in v0.11.31
type LimitedPool struct {
// contains filtered or unexported fields
}
LimitedPool 管理多个 levelPool,以支持不同大小的字节切片
func NewLimitedPool ¶ added in v0.11.31
func NewLimitedPool(minSize, maxSize int) *LimitedPool
NewLimitedPool 创建一个新的 LimitedPool,指定最小和最大大小
func (*LimitedPool) Get ¶ added in v0.11.31
func (p *LimitedPool) Get(size int) *[]byte
Get 从池中获取指定大小的字节切片
type Map ¶
type Map[K comparable, V comparable] struct { // contains filtered or unexported fields }
Map 是一个线程安全的映射,使用泛型 K 和 V。
func (*Map[K, V]) CompareAndDelete ¶
CompareAndDelete 比较指定键的值,如果相等则删除该键的值。
func (*Map[K, V]) CompareAndSwap ¶
CompareAndSwap 比较指定键的现有值,如果相等则将其替换为新值。
func (*Map[K, V]) LoadAndDelete ¶
LoadAndDelete 方法从 Map 中加载并删除指定键的值
func (*Map[K, V]) LoadOrStore ¶
LoadOrStore 获取指定键的值,如果不存在则存储新值。
type RLocker ¶ added in v0.11.28
type RLocker interface { RLock() RUnlock() }
RLocker 是一个接口,定义了读锁和解锁的方法
type Set ¶ added in v0.11.6
type Set[K comparable] struct { // contains filtered or unexported fields }
Set 是一个线程安全的集合,使用 Map 实现。
func (*Set[K]) DeleteAll ¶ added in v0.11.6
func (s *Set[K]) DeleteAll(keys ...K)
DeleteAll 从集合中删除多个元素。
type Uint32 ¶ added in v0.11.29
type Uint32 struct {
// contains filtered or unexported fields
}
Uint32 类型,使用 atomic.Uint32 来表示无符号整数
type Uint64 ¶ added in v0.11.29
type Uint64 struct {
// contains filtered or unexported fields
}
Uint64 类型,使用 atomic.Uint64 来表示无符号整数
type Uintptr ¶ added in v0.11.29
type Uintptr struct {
// contains filtered or unexported fields
}
Uintptr 类型,使用 atomic.Uintptr 来表示无符号指针
func NewUintptr ¶ added in v0.11.29
NewUintptr 创建一个新的 Uintptr 实例
type WaitGroup ¶ added in v0.11.29
type WaitGroup struct {
// contains filtered or unexported fields
}
WaitGroup 是一个自定义的等待组,支持并发操作并捕获错误
func NewWaitGroup ¶ added in v0.11.29
NewWaitGroup 创建一个新的 WaitGroup,支持最大并发数量
params:
- catchPanic: 是否捕获 goroutine 中的 panic
- maxChannel: 可选参数,最大并发数量
return:
- *WaitGroup: 返回初始化后的 WaitGroup 实例
func (*WaitGroup) Done ¶ added in v0.11.29
func (h *WaitGroup) Done()
Done 减少等待计数 每当一个 goroutine 完成时调用此方法
func (*WaitGroup) GetChannelSize ¶ added in v0.11.29
GetChannelSize 返回当前通道的可用容量
return:
- int: 当前通道的可用容量
func (*WaitGroup) GetError ¶ added in v0.11.29
GetError 返回错误,如果没有错误则返回 nil
return:
- error: 捕获的错误,如果没有则返回 nil
func (*WaitGroup) Go ¶ added in v0.11.29
func (h *WaitGroup) Go(f func())
Go 启动一个新的 goroutine,并根据需要处理 panic
params:
- f: 要执行的函数