hook

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any[T comparable](items []T, callback func(T) bool) bool

Any 存在指定的值即返回 true

func Deduplication

func Deduplication[T comparable](vs ...T) []T

Deduplication 去重

func DeduplicationFunc

func DeduplicationFunc[T comparable](vs []T, fn func(T) string) []T

DeduplicationFunc 自定义条件去重

func FileMD5 added in v1.2.3

func FileMD5(r io.Reader) (string, error)

FileMD5 通过缓冲区计算文件的 md5

func MD5

func MD5(s string) string

MD5 计算 md5

func NextTimeTomorrow added in v1.2.9

func NextTimeTomorrow(hour, minute, second int) time.Duration

NextTimeTomorrow 计算距离明天指定时间还有多久 hour: 0-23, minute: 0-59, second: 0-59 返回距离明天指定时间的时长

func NextTimeWithFirst added in v1.2.9

func NextTimeWithFirst(firstWait time.Duration, fn func() time.Duration) func() time.Duration

NextTimeWithFirst 创建一个闭包函数,第一次调用返回 firstWait,之后调用返回 fn() 的结果

func Reverse

func Reverse[T any](s []T) []T

Reverse 反转数组

func Unique

func Unique[T comparable](values []T) bool

Unique 切片中所有值都是唯一,返回 true

func UseMemoryUsage added in v1.2.3

func UseMemoryUsage() func() uint64

UseMemoryUsage 计算内存占用 cost := UseMemoryUsage() defer cost()

func UseTimer added in v1.2.9

func UseTimer(ctx context.Context, fn func(), nextTime func() time.Duration)

func UseTiming

func UseTiming(limit time.Duration) func() time.Duration

UseTiming 计算函数花销,超过 limit 用 error 级别记录 cost := UseTiming(time.Second) defer cost() 业务操作

func UseTimingWithLog added in v1.2.5

func UseTimingWithLog(limit time.Duration) func()

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

func UseTTLCache[K comparable, V any](timeline time.Duration, fn func(K) (V, error)) CacheFn[K, V]

UseTTLCache 使用内存缓存一些临时数据 指定时间超时自动清理

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL