Documentation
¶
Index ¶
- func Any[T comparable](items []T, callback func(T) bool) bool
- func Deduplication[T comparable](vs ...T) []T
- func DeduplicationFunc[T comparable](vs []T, fn func(T) string) []T
- func IntsToMap(s ...int) map[int]struct{}
- func IntsToStrings(s ...int) []string
- func MD5(s string) string
- func MD5FromBytes(s []byte) string
- func MD5FromIO(r io.Reader) (string, error)
- func NextTimeTomorrow(hour, minute, second int) time.Duration
- func NextTimeWithFirst(firstWait time.Duration, fn func() time.Duration) func() time.Duration
- func Reverse[T any](s []T) []T
- func StringsToInts(s ...string) []int
- func StringsToMap(s ...string) map[string]struct{}
- func Unique[T comparable](values []T) bool
- func UseMemoryUsage() func() uint64
- func UsePProf(w io.WriteCloser) func()
- func UseTimer(ctx context.Context, fn func(), nextTime func() time.Duration)
- func UseTiming(limit time.Duration) func() time.Duration
- func UseTimingWithLog(limit time.Duration) func()
- type CacheFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeduplicationFunc ¶
func DeduplicationFunc[T comparable](vs []T, fn func(T) string) []T
DeduplicationFunc 自定义条件去重
func IntsToStrings ¶ added in v1.3.7
IntsToStrings 将整数数组转换为字符串数组
func NextTimeTomorrow ¶ added in v1.2.9
NextTimeTomorrow 计算距离明天指定时间还有多久 hour: 0-23, minute: 0-59, second: 0-59 返回距离明天指定时间的时长
func NextTimeWithFirst ¶ added in v1.2.9
NextTimeWithFirst 创建一个闭包函数,第一次调用返回 firstWait,之后调用返回 fn() 的结果
func StringsToInts ¶ added in v1.3.7
StringsToInts 将字符串数组转换为整数数组
func StringsToMap ¶ added in v1.3.7
StringsToMap 将字符串数组转换为字符串映射
func UseMemoryUsage ¶ added in v1.2.3
func UseMemoryUsage() func() uint64
UseMemoryUsage 计算内存占用 cost := UseMemoryUsage() defer cost()
func UsePProf ¶ added in v1.3.10
func UsePProf(w io.WriteCloser) func()
UsePProf 使用pprof记录cpu profile 如果w为nil,则创建一个文件,文件名称为当前文件的文件名和行号,以及当前时间的年月日 返回一个函数,调用该函数可以停止pprof记录
func UseTiming ¶
UseTiming 计算函数花销,超过 limit 用 error 级别记录 cost := UseTiming(time.Second) defer cost() 业务操作
func UseTimingWithLog ¶ added in v1.2.5
UseTimingWithLog 计算函数花销,超过 limit 用 error 级别记录
Types ¶
type CacheFn ¶
type CacheFn[K comparable, V any] func(K) (V, bool, error)
CacheFn 缓存函数
func UseCache ¶
func UseCache[K comparable, V any](fn func(K) (V, error)) CacheFn[K, V]
UseCache 使用内存缓存一些临时数据 由于是临时数据,其 value 应该是一次性数据,用完即丢 第二个返回参数用来标识是否命中缓存
func UseTTLCache ¶
UseTTLCache 使用内存缓存一些临时数据 指定时间超时自动清理