Documentation ¶
Index ¶
- Constants
- Variables
- func Abs[T NumberType](i T) T
- func BackoffDelay(attempts int) time.Duration
- func CRC32Sum(value []byte) string
- func CopyFile(src, dst string) (err error)
- func CopySlice[T any](src []T) []T
- func DJB33(seed uint32, k string) uint32
- 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 GetField(object any, key string) (any, error)
- func GetHostAddr(host string) (string, error)
- func GetHostTLD(host string) (string, error)
- func GetStringsByField[T any](object []T, key string) ([]string, error)
- func HashString(mode HashMode, s ...string) string
- 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 LoadJson(path string, payload any) error
- func MD5Sum(value []byte) string
- func MakeDirs(path string, strict ...bool) error
- func MapKeyToSlice[T1 comparable, T2 any](m map[T1]T2) []T1
- func MapValueToSlice[T1 comparable, T2 any](m map[T1]T2) []T2
- func Md5Hmac(value, salt string) string
- func MergeSlice[T any](slices ...[]T) []T
- func Monotonic() time.Duration
- func NowUnix() int64
- 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 SaveBuff(path string, payload []byte, overwrite ...bool) error
- func SaveJson(path string, payload any, overwrite ...bool) error
- func Sha1Hmac(value, salt string) string
- func Sha1Sum(value []byte) string
- func Sha256Hmac(value, salt string) string
- func Sha256Sum(value []byte) 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 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 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 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 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 SizeBuff
- type SortAbleSlice
- type SortAbleType
- type SyncMap
- 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)
- type UnsignedIntType
Constants ¶
const ( Linux = runtime.GOOS == "linux" Windows = runtime.GOOS == "windows" )
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, } )
Functions ¶
func Abs ¶
func Abs[T NumberType](i T) T
func BackoffDelay ¶
func DownloadToFolder ¶
DownloadToFolder 下载文件到目录
func ExpireTime ¶
func FromBase62 ¶
func GetHostAddr ¶
func GetHostTLD ¶
func HashString ¶
func IntSliceToString ¶
IntSliceToString int类型转换string
func IntToString ¶
func IsSafePathName ¶
func IsSafeUnixLikePath ¶
func JsonConvert ¶
func MapKeyToSlice ¶
func MapKeyToSlice[T1 comparable, T2 any](m map[T1]T2) []T1
MapKeyToSlice map key转换成列表
func MapValueToSlice ¶
func MapValueToSlice[T1 comparable, T2 any](m map[T1]T2) []T2
MapValueToSlice map 值转换成列表
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 Sha256Hmac ¶
func SliceReverse ¶
func SliceReverse[T any](s []T) []T
func SliceToMap ¶
func SliceToMap[T any, K comparable](s []T, keyFunc func(T) K) map[K]T
func SliceToMapByField ¶
func SliceToMapByField[T any, K comparable](s []T, field ...string) (map[K]T, error)
func SliceToMapByStringField ¶
func SortedQuery ¶
SortedQuery 按照key升序的顺序生成的query string
func StringSliceToInt ¶
StringSliceToInt string 转换未int
func StringToInt ¶
func ToBase62Bytes ¶
func UnSafeGetStringsByField ¶
func UnsafeStrToI32 ¶
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 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 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]