utils

package
v0.0.0-...-3c4a07b Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayKeys

func ArrayKeys[K comparable, V any](m map[K]V) []K

func ArrayValues

func ArrayValues[K comparable, V any](m map[K]V) []V

func CallbackGo

func CallbackGo(fn func(), callback func())

CallbackGo 安全使用go的同时,额外的保证在goroutine执行结束后调用回调函数,即使panic也会出发回调

func Chunk

func Chunk[T any](data []T, size int) [][]T

func Filter

func Filter[T any](data []T, f func(T) bool) []T

func FindIndex

func FindIndex[T any](data []T, f func(T) bool) int

func FindItem

func FindItem[T comparable](data []T, target T) int

func ForEach

func ForEach[T any](data []T, f func(T) error) error

func GenerateCacheKey

func GenerateCacheKey(v interface{}) (string, error)

GenerateCacheKey 生成缓存key

func InArray

func InArray[T comparable](target T, data []T) bool

func Map

func Map[T any, K any](data []T, f func(T) K) []K

func MapByKey

func MapByKey[T any, K comparable](base []T, keyFunc func(T) K) map[K]T

func MapColumn

func MapColumn[T any, U any](slice []T, extractor func(T) U) []U

func Reverse

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

Reverse 反转切片(原地反转)

func SafeGo

func SafeGo(fn func())

SafeGo 安全的使用goroutine

func SetPanicHandler

func SetPanicHandler(hd func(info interface{}))

SetPanicHandler 统一将goroutine的panic管理起来

func Unique

func Unique[T comparable](data []T) []T

Types

type CacheItem

type CacheItem struct {
	Data      interface{} // 缓存数据
	Timestamp time.Time   // 时间戳
}

CacheItem 缓存项结构体

type LocalCache

type LocalCache struct {
	// contains filtered or unexported fields
}

LocalCache 本地缓存结构体

func NewLocalCache

func NewLocalCache(expire time.Duration) *LocalCache

NewLocalCache 创建新的本地缓存实例

func (*LocalCache) Clear

func (lc *LocalCache) Clear()

Clear 清空所有缓存

func (*LocalCache) Delete

func (lc *LocalCache) Delete(key string)

Delete 删除缓存数据

func (*LocalCache) Get

func (lc *LocalCache) Get(key string) (interface{}, bool)

Get 从缓存获取数据

func (*LocalCache) GetOrSet

func (lc *LocalCache) GetOrSet(key string, fn func() (interface{}, error)) (interface{}, bool, error)

GetOrSet 从缓存获取数据,如果不存在则执行函数获取并设置缓存

func (*LocalCache) Set

func (lc *LocalCache) Set(key string, data interface{})

Set 设置缓存数据

type OnceErr

type OnceErr struct {
	// contains filtered or unexported fields
}

func (*OnceErr) Error

func (n *OnceErr) Error() error

func (*OnceErr) SetError

func (n *OnceErr) SetError(err error)

SetError ...

Jump to

Keyboard shortcuts

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