utils

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

@Title @Description @Author Wangwengang 2023/12/12 14:17 @Update Wangwengang 2023/12/12 14:17

@Title @Description @Author Wangwengang 2023/12/12 09:15 @Update Wangwengang 2023/12/12 09:15

@Title @Description @Author Wangwengang 2023/12/10 12:44 @Update Wangwengang 2023/12/10 12:44

Index

Constants

View Source
const (
	Prime   = 16777619
	HashVal = 2166136261
)

Variables

View Source
var AcceptDelay *acceptDelay
View Source
var ShardCount = 32

Functions

func ByteArrayToString

func ByteArrayToString(buf [][][]byte) string

func CreateDir

func CreateDir(dirs ...string) (err error)

func DeLFile

func DeLFile(filePath string) error

func FileExist

func FileExist(path string) bool

FileExist 判断文件是否存在

func FileMove

func FileMove(src string, dst string) (err error)

func GenerateAESKey

func GenerateAESKey(keySize int) (string, error)

GenerateAESKey 生成指定字节长度的随机密钥 选择密钥长度:16 (128-bit), 24 (192-bit), 32 (256-bit)

func GenerateRandomString

func GenerateRandomString(length int) (string, error)

GenerateRandomString 生成随机字符串 length为字节长度,编码后长度会不同

func GenerateTLSConfig

func GenerateTLSConfig() (*tls.Config, error)

func HmacSha1

func HmacSha1(key, data []byte) []byte

func MD5V

func MD5V(str []byte, b ...byte) string

func PathExists

func PathExists(path string) (bool, error)

func ReverseByteArray

func ReverseByteArray(s [][][]byte) [][][]byte

func StrToInt64

func StrToInt64(str string) int64

如果不是int64类型的string会返回0,务必确保是int64

func Tail

func Tail(path string, num int) string

func TrimSpace

func TrimSpace(target interface{})

Types

type BrotliCompressor

type BrotliCompressor struct{}

func (BrotliCompressor) Unzip

func (c BrotliCompressor) Unzip(data []byte) ([]byte, error)

func (BrotliCompressor) Zip

func (c BrotliCompressor) Zip(data []byte) ([]byte, error)

type Fnv32Hash

type Fnv32Hash struct{}

func (*Fnv32Hash) Sum

func (f *Fnv32Hash) Sum(key string) uint32

fnv32 algorithm

type IDWorker

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

func NewIDWorker

func NewIDWorker(workerId int64) (*IDWorker, error)

func (*IDWorker) NextID

func (w *IDWorker) NextID() (int64, error)

type IHash

type IHash interface {
	Sum(string) uint32
}

func DefaultHash

func DefaultHash() IHash

type IterCb

type IterCb func(key string, v interface{})

IterCb Iterator callback,called for every key,value found in maps. RLock is held for all calls for a given shard therefore callback sess consistent view of a shard, but not across the shards

type RemoveCb

type RemoveCb func(key string, v interface{}, exists bool) bool

RemoveCb is a callback executed in a map.RemoveCb() call, while Lock is held If returns true, the element will be removed from the map

type ShardLockMaps

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

ShardLockMaps A "thread" safe map of type string:Anything. To avoid lock bottlenecks this map is dived to several (ShardCount) map shards.

func NewShardLockMaps

func NewShardLockMaps() ShardLockMaps

NewShardLockMaps Creates a new ShardLockMaps.

func NewWithCustomHash

func NewWithCustomHash(hash IHash) ShardLockMaps

func (ShardLockMaps) Clear

func (slm ShardLockMaps) Clear()

Clear removes all items from map.

func (ShardLockMaps) Count

func (slm ShardLockMaps) Count() int

Count returns the number of elements within the map.

func (ShardLockMaps) Get

func (slm ShardLockMaps) Get(key string) (interface{}, bool)

Get retrieves an element from map under given key.

func (ShardLockMaps) GetShard

func (slm ShardLockMaps) GetShard(key string) *SingleShardMap

GetShard returns shard under given key

func (ShardLockMaps) Has

func (slm ShardLockMaps) Has(key string) bool

Has Looks up an item under specified key

func (ShardLockMaps) IsEmpty

func (slm ShardLockMaps) IsEmpty() bool

IsEmpty checks if map is empty.

func (ShardLockMaps) Items

func (slm ShardLockMaps) Items() map[string]interface{}

Items returns all items as map[string]interface{}

func (ShardLockMaps) IterBuffered

func (slm ShardLockMaps) IterBuffered() <-chan Tuple

IterBuffered returns a buffered iterator which could be used in a for range loop.

func (ShardLockMaps) IterCb

func (slm ShardLockMaps) IterCb(fn IterCb)

IterCb Callback based iterator, cheapest way to read all elements in a map.

func (ShardLockMaps) Keys

func (slm ShardLockMaps) Keys() []string

Keys returns all keys as []string

func (ShardLockMaps) MSet

func (slm ShardLockMaps) MSet(data map[string]interface{})

MSet Sets the given value under the specified key.

func (ShardLockMaps) MarshalJSON

func (slm ShardLockMaps) MarshalJSON() ([]byte, error)

MarshalJSON Reviles ConcurrentMap "private" variables to json marshal.

func (ShardLockMaps) Pop

func (slm ShardLockMaps) Pop(key string) (v interface{}, exists bool)

Pop removes an element from the map and returns it

func (ShardLockMaps) Remove

func (slm ShardLockMaps) Remove(key string)

Remove removes an element from the map.

func (ShardLockMaps) RemoveCb

func (slm ShardLockMaps) RemoveCb(key string, cb RemoveCb) bool

RemoveCb locks the shard containing the key, retrieves its current value and calls the callback with those params If callback returns true and element exists, it will remove it from the map Returns the value returned by the callback (even if element was not present in the map)

func (ShardLockMaps) Set

func (slm ShardLockMaps) Set(key string, value interface{})

Set Sets the given value under the specified key.

func (ShardLockMaps) SetNX

func (slm ShardLockMaps) SetNX(key string, value interface{}) bool

SetNX Sets the given value under the specified key if no value was associated with it.

func (ShardLockMaps) UnmarshalJSON

func (slm ShardLockMaps) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON Reverse process of Marshal.

type SingleShardMap

type SingleShardMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

SingleShardMap A "thread" safe string to anything map.

type Tuple

type Tuple struct {
	Key string
	Val interface{}
}

Tuple Used by the IterBuffered functions to wrap two variables together over a channel,

Jump to

Keyboard shortcuts

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