Documentation
¶
Index ¶
- Constants
- Variables
- func Abs[T NumberType](i T) T
- func AppendMaps[T any](sources ...map[string]T) map[string]T
- func BackoffDelay(attempts int) time.Duration
- func CRC32Sum(value []byte) string
- func CopyFile(src, dst string) (err error)
- func CopyMap[M ~map[K]V, K comparable, V any](m M) M
- func CopySlice[T any](src []T) []T
- func DJB33(seed uint32, k string) uint32
- func DeepCopyMap[T any](src map[string]T) (map[string]T, error)
- func DownloadToBuffer(url string, writer io.Writer) error
- func DownloadToFile(url, path string) (err error)
- func DownloadToFolder(url, folder string) (err error)
- func ExpireTime(timeout int64) (int64, int64)
- func FromBase62(s string) (n int, err error)
- func GetAllFiles(root, suffix string, total int) ([]string, error)
- func GetDay(at ...int64) int64
- func GetField(object any, key string) (any, error)
- func GetHostAddr(host string) (string, error)
- func GetHostTLD(host string) (string, error)
- func GetMonday(at ...int64) int64
- func GetMonth(at ...int64) int64
- func GetNextDay(at ...int64) int64
- func GetNextMonth(at ...int64) int64
- func GetNextYear(at ...int64) int64
- func GetStringsByField[T any](object []T, key string) ([]string, error)
- func GetYear(at ...int64) int64
- func HasIntersection[T comparable](slice1, slice2 []T) bool
- func HashString(mode HashMode, s ...string) string
- func HashStringToInt(s string, min, max int) int
- func HostPort(addr string, port interface{}) string
- func IPs() []string
- func IncludeInSlice[T comparable](s []T, target T) bool
- func InsertSlice[T any](s []T, value T) []T
- func IntSliceToString[T IntType](s []T) []string
- func IntToString[T IntType](value T) string
- func IsLocal(addr string) bool
- func IsSafePathName(name string) bool
- func IsSafeUnixLikePath(path string) bool
- func JsonConvert(a, b any) error
- func Listen(addr string) (net.Listener, error)
- func LoadBuff(path string) ([]byte, error)
- func LoadGeneralJsonFiles(targets []string, skip bool, loop int) (map[string]any, error)
- func LoadJson(path string, payload any) error
- func MD5Sum(value []byte) string
- func MakeDirs(path string, strict ...bool) error
- func MapClear[M ~map[K]V, K comparable, V any](m M)
- func MapKeyToSlice[T1 comparable, T2 any](m map[T1]T2) []T1
- func MapKeys[M ~map[K]V, K comparable, V any](m M) []K
- func MapToSliceByField[T any, K comparable](s []T, field ...string) (map[K]T, error)
- func MapValueToSlice[T1 comparable, T2 any](m map[T1]T2) []T2
- func MapValues[M ~map[K]V, K comparable, V any](m M) []V
- func Md5Hmac(value, key []byte) string
- func MergeJsonMaps(dest, src map[string]any) map[string]any
- func MergeMaps[T any](sources ...map[string]T) (map[string]T, error)
- func MergeSlice[T any](slices ...[]T) []T
- func MergeSliceMaps[T any](key string, sources ...any) (map[string]T, error)
- func Monotonic() time.Duration
- func New62Sqid(len uint8) (*sqids.Sqids, error)
- func Now() time.Time
- func NowUnix() int64
- func NumberSliceJoin[T NumberType](values []T) string
- func OrderedQuery(values *OrderedMap[string, string]) string
- func ParseQuery(query string) (values map[string]string, err error)
- func PathExist(path string) (bool, error)
- func PathFileInfo(path string) (os.FileInfo, error)
- func PathIsDir(path string) (bool, error)
- func PathIsRegularFile(path string) (bool, error)
- func PathIsUnixSockFile(path string) (bool, error)
- func PopQuery(query string, skip ...string) (string, error)
- func RandString(n int) string
- func RandomHex(length int) string
- func RandomInt(n int) int
- func ReadFile(path string) ([]byte, error)
- func RemoveElementSlice[T comparable](sp *[]T, target T)
- func RepeatSlice[T any](slice []T, times int) []T
- func SaveBuff(path string, payload []byte, overwrite ...bool) error
- func SaveJson(path string, payload any, overwrite ...bool) error
- func Sets[T comparable](slices []T) []T
- func Sha1Hmac(value, key []byte) string
- func Sha1Sum(value []byte) string
- func Sha256Hmac(value, key []byte) string
- func Sha256Sum(value []byte) string
- func ShuffleSlice[T any](list []T) []T
- func SliceJoin[T SortAbleType](values []T, quote string, split ...string) string
- func SliceReverse[T any](s []T) []T
- func SliceToMap[T any, K comparable](s []T, keyFunc func(T) K) map[K]T
- func SliceToMapByField[T any, K comparable](s []T, field ...string) (map[K]T, error)
- func SliceToMapByStringField[T any](s []T, key ...string) (map[string]T, error)
- func SortSlice[T SortAbleType](src []T, reverse ...bool) []T
- func SortedQuery(values map[string]string) string
- func SplitSlice[T any](slice []T, total int) [][]T
- func StrSliceJoin(values []string) string
- func StrToI32(value string) (int32, error)
- func StringSliceToInt[T IntType](s []string) ([]T, error)
- func StringToInt(value string) (int, error)
- func StringToMoney(s string) (value decimal.Decimal, err error)
- func StringToTime(s string) (time.Time, error)
- func Supported(supports []string, target string) bool
- func ToBase62(n int) string
- func ToBase62Bytes(n int) (s []byte)
- func ToString(i any) (string, error)
- func TopLevelDomain(domain string) (string, error)
- func UnSafeGetStringsByField[T any](object []T, key string) []string
- func UnZip(source, output string) error
- func UnsafeStrToI32(value string) int32
- func UnsafeStrToI64(value string) int64
- func UnsafeToString(i any) string
- func VerifyAddr(listen string) bool
- func VerifyIP(addr string) (string, error)
- func Zip(source, output string) error
- func ZipCompress(data []byte) ([]byte, error)
- func ZipDecompress(data []byte) ([]byte, error)
- func ZipFileBuff(name string, data []byte) ([]byte, error)
- type BaseType
- type Element
- type ExpireMap
- func (m *ExpireMap[K, V]) All() map[K]V
- func (m *ExpireMap[K, V]) Delete(key K)
- func (m *ExpireMap[K, V]) DeleteAll()
- func (m *ExpireMap[K, V]) Len() int
- func (m *ExpireMap[K, V]) Load(key K, expired bool) (V, bool)
- func (m *ExpireMap[K, V]) LoadOrStore(key K, value V, expire int64) (V, bool)
- func (m *ExpireMap[K, V]) Store(key K, value V, expire int64)
- func (m *ExpireMap[K, V]) SyncLoad(key K) (V, bool)
- type ExpiredItem
- type HashMode
- type IntType
- type KeyLocks
- type NumberType
- type OrderedMap
- func (m *OrderedMap[K, V]) Back() *Element[K, V]
- func (m *OrderedMap[K, V]) Copy() *OrderedMap[K, V]
- func (m *OrderedMap[K, V]) Delete(key K) (didDelete bool)
- func (m *OrderedMap[K, V]) Front() *Element[K, V]
- func (m *OrderedMap[K, V]) Get(key K) (value V, ok bool)
- func (m *OrderedMap[K, V]) GetElement(key K) *Element[K, V]
- func (m *OrderedMap[K, V]) GetOrDefault(key K, defaultValue V) V
- func (m *OrderedMap[K, V]) Keys() (keys []K)
- func (m *OrderedMap[K, V]) Len() int
- func (m *OrderedMap[K, V]) ReplaceKey(originalKey, newKey K) bool
- func (m *OrderedMap[K, V]) Set(key K, value V) bool
- type Sequence
- type SizeBuff
- type SortAbleSlice
- type SortAbleType
- type SyncMap
- func (m *SyncMap[K, V]) All() map[K]V
- func (m *SyncMap[K, V]) Delete(key K)
- func (m *SyncMap[K, V]) DeleteAll()
- func (m *SyncMap[K, V]) Len() int
- func (m *SyncMap[K, V]) Load(key K) (value V, ok bool)
- func (m *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m *SyncMap[K, V]) Range(f func(key K, value V) bool)
- func (m *SyncMap[K, V]) Store(key K, value V)
- func (m *SyncMap[K, V]) Swap(key K, value V) (previous V, loaded bool)
- type UnsignedIntType
- type Versioned
- type VersionedMap
- func (m *VersionedMap[K, V]) Clear()
- func (m *VersionedMap[K, V]) Clone() map[K]V
- func (m *VersionedMap[K, V]) Keys() []K
- func (m *VersionedMap[K, V]) Len() int
- func (m *VersionedMap[K, V]) Load(key K) (V, bool)
- func (m *VersionedMap[K, V]) LoadAndDelete(key K) (V, bool)
- func (m *VersionedMap[K, V]) LoadOrStore(key K, value V) (ret V, find bool)
- func (m *VersionedMap[K, V]) Store(key K, value V)
- func (m *VersionedMap[K, V]) StoreNew(key K, value V) bool
- func (m *VersionedMap[K, V]) Values() []V
Constants ¶
const ( Base62Chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" Base62CharsLen = len(Base62Chars) Linux = runtime.GOOS == "linux" Windows = runtime.GOOS == "windows" )
const (
TimestampFormat = "2006-01-02 15:04:05"
)
Variables ¶
var ( TypeOfError = reflect.TypeOf((*error)(nil)).Elem() TypeOfBytes = reflect.TypeOf(([]byte)(nil)) TypeOfContext = reflect.TypeOf(new(context.Context)).Elem() TypeOfProtoMsg = reflect.TypeOf(new(proto.Message)).Elem() TypesOfBaseType = []reflect.Kind{ reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128, reflect.String, } )
var (
RandomSeed *rand.Rand
)
Functions ¶
func Abs ¶
func Abs[T NumberType](i T) T
func BackoffDelay ¶
func DeepCopyMap ¶
DeepCopyMap 通过序列号深拷贝
func DownloadToFolder ¶
DownloadToFolder 下载文件到目录
func ExpireTime ¶
func FromBase62 ¶
func GetHostAddr ¶
func GetHostTLD ¶
func HasIntersection ¶
func HasIntersection[T comparable](slice1, slice2 []T) bool
HasIntersection 判断是否有交集
func HashString ¶
func HashStringToInt ¶
HashStringToInt hashes a string to an int value and limits the result within a specified range. 用于散列字符串到分区 [a, b)
func IntSliceToString ¶
IntSliceToString int类型转换string
func IntToString ¶
func IsSafePathName ¶
func IsSafeUnixLikePath ¶
func JsonConvert ¶
func LoadGeneralJsonFiles ¶
func MapClear ¶
func MapClear[M ~map[K]V, K comparable, V any](m M)
func MapKeyToSlice ¶
func MapKeyToSlice[T1 comparable, T2 any](m map[T1]T2) []T1
MapKeyToSlice map key转换成列表
func MapKeys ¶
func MapKeys[M ~map[K]V, K comparable, V any](m M) []K
func MapToSliceByField ¶
func MapToSliceByField[T any, K comparable](s []T, field ...string) (map[K]T, error)
MapToSliceByField 提取结构体中的自定字段转为列表
func MapValueToSlice ¶
func MapValueToSlice[T1 comparable, T2 any](m map[T1]T2) []T2
MapValueToSlice map 值转换成列表
func MapValues ¶
func MapValues[M ~map[K]V, K comparable, V any](m M) []V
func MergeSliceMaps ¶
MergeSliceMaps 通过序列号深拷贝后合并
func OrderedQuery ¶
func OrderedQuery(values *OrderedMap[string, string]) string
OrderedQuery 按照字典写入顺的生成query string
func ParseQuery ¶
ParseQuery query string转化为map
func PathIsRegularFile ¶
func PathIsUnixSockFile ¶
func RemoveElementSlice ¶
func RemoveElementSlice[T comparable](sp *[]T, target T)
RemoveElementSlice 从列表中剔除元素(不创建新列表)
func RepeatSlice ¶
RepeatSlice 实现python [1] * n的功能
func Sets ¶
func Sets[T comparable](slices []T) []T
func Sha256Hmac ¶
func SliceJoin ¶
func SliceJoin[T SortAbleType](values []T, quote string, split ...string) string
SliceJoin 列表合并
func SliceToMap ¶
func SliceToMap[T any, K comparable](s []T, keyFunc func(T) K) map[K]T
SliceToMap 列表传字典,key通过传入的keyFunc 获取
func SliceToMapByField ¶
func SliceToMapByField[T any, K comparable](s []T, field ...string) (map[K]T, error)
SliceToMapByField 列表转字典,以列表中结构体的指定字段为key
func SliceToMapByStringField ¶
SliceToMapByStringField 列表转字典,以列表中结构体的指定字符串字段为key
func SortedQuery ¶
SortedQuery 按照key升序的顺序生成的query string
func SplitSlice ¶
func StringSliceToInt ¶
StringSliceToInt string 转换未int
func StringToInt ¶
func ToBase62Bytes ¶
func UnSafeGetStringsByField ¶
func UnsafeStrToI32 ¶
func UnsafeStrToI64 ¶
func UnsafeToString ¶
func VerifyAddr ¶
func VerifyIP ¶
VerifyIP (Extract) returns a valid IP address. If the address provided is a valid address, it will be returned directly. Otherwise the available interfaces be itterated over to find an IP address, prefferably private.
func ZipCompress ¶
func ZipDecompress ¶
Types ¶
type Element ¶
type Element[K comparable, V any] struct { // The key that corresponds to this element in the ordered map. Key K // The value stored with this element. Value V // contains filtered or unexported fields }
Element is an element of a null terminated (non circular) intrusive doubly linked list that contains the key of the correspondent element in the ordered map too.
type ExpireMap ¶
type ExpireMap[K comparable, V any] struct { // contains filtered or unexported fields }
func NewExpireMap ¶
func (*ExpireMap[K, V]) LoadOrStore ¶
LoadOrStore 存储或者加载( ok表示加载成功)
type ExpiredItem ¶
type KeyLocks ¶
type KeyLocks struct {
// contains filtered or unexported fields
}
func NewKeyLocks ¶
func NewKeyLocks() *KeyLocks
type NumberType ¶
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
func NewOrderedMap ¶
func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]
func (*OrderedMap[K, V]) Back ¶
func (m *OrderedMap[K, V]) Back() *Element[K, V]
Back will return the element that is the last (most recent Set element). If there are no elements this will return nil.
func (*OrderedMap[K, V]) Copy ¶
func (m *OrderedMap[K, V]) Copy() *OrderedMap[K, V]
Copy returns a new OrderedMap with the same elements. Using Copy while there are concurrent writes may mangle the result.
func (*OrderedMap[K, V]) Delete ¶
func (m *OrderedMap[K, V]) Delete(key K) (didDelete bool)
Delete will remove a key from the map. It will return true if the key was removed (the key did exist).
func (*OrderedMap[K, V]) Front ¶
func (m *OrderedMap[K, V]) Front() *Element[K, V]
Front will return the element that is the first (oldest Set element). If there are no elements this will return nil.
func (*OrderedMap[K, V]) Get ¶
func (m *OrderedMap[K, V]) Get(key K) (value V, ok bool)
Get returns the value for a key. If the key does not exist, the second return parameter will be false and the value will be nil.
func (*OrderedMap[K, V]) GetElement ¶
func (m *OrderedMap[K, V]) GetElement(key K) *Element[K, V]
GetElement returns the element for a key. If the key does not exist, the pointer will be nil.
func (*OrderedMap[K, V]) GetOrDefault ¶
func (m *OrderedMap[K, V]) GetOrDefault(key K, defaultValue V) V
GetOrDefault returns the value for a key. If the key does not exist, returns the default value instead.
func (*OrderedMap[K, V]) Keys ¶
func (m *OrderedMap[K, V]) Keys() (keys []K)
Keys returns all of the keys in the order they were inserted. If a key was replaced it will retain the same position. To ensure most recently set keys are always at the end you must always Delete before Set.
func (*OrderedMap[K, V]) Len ¶
func (m *OrderedMap[K, V]) Len() int
Len returns the number of elements in the map.
func (*OrderedMap[K, V]) ReplaceKey ¶
func (m *OrderedMap[K, V]) ReplaceKey(originalKey, newKey K) bool
ReplaceKey replaces an existing key with a new key while preserving order of the value. This function will return true if the operation was successful, or false if 'originalKey' is not found OR 'newKey' already exists (which would be an overwrite).
func (*OrderedMap[K, V]) Set ¶
func (m *OrderedMap[K, V]) Set(key K, value V) bool
Set will set (or replace) a value for a key. If the key was new, then true will be returned. The returned value will be false if the value was replaced (even if the value was the same).
type Sequence ¶
type Sequence struct {
// contains filtered or unexported fields
}
func NewSequence ¶
NewSequence 创建数字转字符串的序列化对象 @param chars 可用的字符串 @param length 输出最大长度 @param bulk 并发队列书香,默认4
type SizeBuff ¶
type SizeBuff struct {
// contains filtered or unexported fields
}
SizeBuff 有最大值限制的buff
func NewSizeBuff ¶
type SortAbleSlice ¶
type SortAbleSlice[T SortAbleType] []T
SortAbleSlice 可排序列表,从小到大
func (SortAbleSlice[T]) Len ¶
func (x SortAbleSlice[T]) Len() int
func (SortAbleSlice[T]) Less ¶
func (x SortAbleSlice[T]) Less(i, j int) bool
func (SortAbleSlice[T]) Swap ¶
func (x SortAbleSlice[T]) Swap(i, j int)
type SortAbleType ¶
type SyncMap ¶
type SyncMap[K comparable, V any] struct { // contains filtered or unexported fields }
func NewSyncMap ¶
func NewSyncMap[K comparable, V any]() *SyncMap[K, V]
func (*SyncMap[K, V]) LoadAndDelete ¶
func (*SyncMap[K, V]) LoadOrStore ¶
type UnsignedIntType ¶
type VersionedMap ¶
type VersionedMap[K comparable, V Versioned] struct { // contains filtered or unexported fields }
func NewVersionedMap ¶
func NewVersionedMap[K comparable, V Versioned]() *VersionedMap[K, V]
func (*VersionedMap[K, V]) Clear ¶
func (m *VersionedMap[K, V]) Clear()
func (*VersionedMap[K, V]) Clone ¶
func (m *VersionedMap[K, V]) Clone() map[K]V
func (*VersionedMap[K, V]) Keys ¶
func (m *VersionedMap[K, V]) Keys() []K
func (*VersionedMap[K, V]) Len ¶
func (m *VersionedMap[K, V]) Len() int
func (*VersionedMap[K, V]) Load ¶
func (m *VersionedMap[K, V]) Load(key K) (V, bool)
func (*VersionedMap[K, V]) LoadAndDelete ¶
func (m *VersionedMap[K, V]) LoadAndDelete(key K) (V, bool)
func (*VersionedMap[K, V]) LoadOrStore ¶
func (m *VersionedMap[K, V]) LoadOrStore(key K, value V) (ret V, find bool)
LoadOrStore 存储一个值、find表示值存在,没有进行存储
func (*VersionedMap[K, V]) Store ¶
func (m *VersionedMap[K, V]) Store(key K, value V)
func (*VersionedMap[K, V]) StoreNew ¶
func (m *VersionedMap[K, V]) StoreNew(key K, value V) bool
StoreNew 存储一个新值、返回值表示是否存储成功
func (*VersionedMap[K, V]) Values ¶
func (m *VersionedMap[K, V]) Values() []V