utils

package
v0.0.0-...-78a0d84 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NullData      = []byte("{}")
	NullDataEx    = []byte("")
	TypeOfContext = reflect.TypeOf((*context.Context)(nil)).Elem()
	TypeOfError   = reflect.TypeOf((*error)(nil)).Elem()
	TypeOfInt     = reflect.TypeOf((*int)(nil)).Elem()
)
View Source
var (
	GenerateIdError = errors.New("Generate Id failed")
)
View Source
var SliceIsNilError = errors.New("slice is nil")

Functions

func CollectId

func CollectId(id uint64)

func DelMapContext

func DelMapContext(ctx context.Context, key interface{})

func DeleteSlice

func DeleteSlice(slice interface{}, index int) (interface{}, error)

func GetAvailableId

func GetAvailableId() uint64

func GetContextMap

func GetContextMap(ctx context.Context) (m *sync.Map, ok bool)

func GetId

func GetId() uint64

func GetMapContext

func GetMapContext(ctx context.Context, key interface{}) interface{}

func GetNowTimeMillisecond

func GetNowTimeMillisecond() int64

func IF

func IF(b bool, t1, t2 interface{}) interface{}

func NewContextMap

func NewContextMap(ctx context.Context) context.Context

func NowTimeFormat

func NowTimeFormat() string

func OnServiceHandle

func OnServiceHandle(session defs.ISession, packet defs.IPacket) bool

func ParseDataByJson

func ParseDataByJson(data []byte, req interface{}) bool

func ParseDataByProtobuf

func ParseDataByProtobuf(data []byte, req interface{}) bool

func ParseMethodNameBySuffix

func ParseMethodNameBySuffix(methodName string) (name string, err error)

func RegisterService

func RegisterService(rcvr interface{})

func SerializeDataByJson

func SerializeDataByJson(d interface{}, param ...interface{}) []byte

func SerializeDataByProtobuf

func SerializeDataByProtobuf(d interface{}, param ...interface{}) []byte

func SetMapContext

func SetMapContext(ctx context.Context, key, value interface{})

func Slice

func Slice(s string) (b []byte)

func String

func String(b []byte) (s string)

func Struct2Map

func Struct2Map(obj interface{}) map[string]interface{}

func WaitExit

func WaitExit(fList ...func())

func WaitSignal

func WaitSignal()

Types

type ConsistentHash

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

func NewConsistentHash

func NewConsistentHash(initReplicasNum ...int) *ConsistentHash

func (*ConsistentHash) Add

func (ch *ConsistentHash) Add(node string)

func (*ConsistentHash) AddNodes

func (ch *ConsistentHash) AddNodes(nodes []string)

func (*ConsistentHash) GetNode

func (ch *ConsistentHash) GetNode(key string) string

func (*ConsistentHash) GetNodeIdx

func (ch *ConsistentHash) GetNodeIdx(hash uint32) int

func (*ConsistentHash) Remove

func (ch *ConsistentHash) Remove(node string)

func (*ConsistentHash) RemoveNodes

func (ch *ConsistentHash) RemoveNodes(nodes []string)

type HeapTimer

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

func NewHeapTimer

func NewHeapTimer(millInterval int64) *HeapTimer

func (*HeapTimer) AddTimer

func (ht *HeapTimer) AddTimer(f func(), millInterval int64, repeat ...bool)

func (*HeapTimer) IsRunning

func (ht *HeapTimer) IsRunning() bool

func (*HeapTimer) Run

func (ht *HeapTimer) Run()

func (*HeapTimer) Stop

func (ht *HeapTimer) Stop()

type IdGenerator

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

func NewIdGenerator

func NewIdGenerator() *IdGenerator

func (*IdGenerator) CycleCount

func (idg *IdGenerator) CycleCount() uint64

func (*IdGenerator) Get

func (idg *IdGenerator) Get() (id uint64)

func (*IdGenerator) GetAvailableId

func (idg *IdGenerator) GetAvailableId() (id uint64)

func (*IdGenerator) Put

func (idg *IdGenerator) Put(id uint64)

type Item

type Item struct {
	Value    interface{}
	Priority int64
	Index    int
}

type PriorityQueue

type PriorityQueue []*Item

func NewPriorityQueue

func NewPriorityQueue(capacity int) PriorityQueue

func (*PriorityQueue) Get

func (pq *PriorityQueue) Get(maxPriority int64) *Item

func (PriorityQueue) Len

func (pq PriorityQueue) Len() int

func (PriorityQueue) Less

func (pq PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Peek

func (pq *PriorityQueue) Peek() *Item

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() interface{}

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x interface{})

func (PriorityQueue) Swap

func (pq PriorityQueue) Swap(i, j int)

func (*PriorityQueue) Update

func (pq *PriorityQueue) Update(item *Item, v interface{}, priority int64)

type SafeQueue

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

func NewSafeQueue

func NewSafeQueue() *SafeQueue

func (*SafeQueue) Empty

func (sq *SafeQueue) Empty() bool

func (*SafeQueue) Put

func (sq *SafeQueue) Put(v interface{})

func (*SafeQueue) Size

func (sq *SafeQueue) Size() int

func (*SafeQueue) Stop

func (sq *SafeQueue) Stop()

func (*SafeQueue) Take

func (sq *SafeQueue) Take(newList *[]interface{})

type ServiceFactory

type ServiceFactory struct {
	ParseMethodNameCallback defs.ParseMethodNameCallback
	ParseDataCallback       defs.ParseDataCallback
	// contains filtered or unexported fields
}

func GetMsgFactory

func GetMsgFactory() *ServiceFactory

func NewServiceFactory

func NewServiceFactory() *ServiceFactory

func (*ServiceFactory) IsExported

func (sf *ServiceFactory) IsExported(name string) bool

func (*ServiceFactory) IsExportedOrBuiltinType

func (sf *ServiceFactory) IsExportedOrBuiltinType(t reflect.Type) bool

func (*ServiceFactory) OnServiceHandle

func (sf *ServiceFactory) OnServiceHandle(session defs.ISession, packet defs.IPacket) bool

func (*ServiceFactory) Register

func (sf *ServiceFactory) Register(rcvr interface{}, cb ...defs.ParseMethodNameCallback)

func (*ServiceFactory) SetParseDataCallback

func (sf *ServiceFactory) SetParseDataCallback(cb defs.ParseDataCallback)

func (*ServiceFactory) SetParseMethodNameCallback

func (sf *ServiceFactory) SetParseMethodNameCallback(cb defs.ParseMethodNameCallback)

func (*ServiceFactory) SetSerializeDataCallback

func (sf *ServiceFactory) SetSerializeDataCallback(cb defs.SerializeDataCallback)

type SortUint32

type SortUint32 []uint32

func (SortUint32) Len

func (su SortUint32) Len() int

func (SortUint32) Less

func (su SortUint32) Less(i, j int) bool

func (SortUint32) Swap

func (su SortUint32) Swap(i, j int)

type Timer

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

func NewTimer

func NewTimer(tick time.Duration, f func()) *Timer

func (*Timer) IsRunning

func (t *Timer) IsRunning() bool

func (*Timer) Start

func (t *Timer) Start(once ...bool)

func (*Timer) Stop

func (t *Timer) Stop()

type Trie

type Trie struct {
	Node *TrieNode
}

func NewTrie

func NewTrie() *Trie

func (*Trie) Add

func (t *Trie) Add(text string)

func (*Trie) Find

func (t *Trie) Find(text string) bool

func (*Trie) Replace

func (t *Trie) Replace(text string) (string, []string)

type TrieNode

type TrieNode struct {
	Children sync.Map //map[rune]*TrieNode
	End      bool
}

func NewTrieNode

func NewTrieNode() *TrieNode

Jump to

Keyboard shortcuts

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