utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitMachineID

func InitMachineID(machineID int16)

snow flakes machine_id: 10 bits machineID + 6 bits plugin_type

func MachineID

func MachineID(id int64) int16

func MachineIDHigh

func MachineIDHigh(id int64) int16

func MachineIDLow

func MachineIDLow(id int64) int16

func NextID

func NextID(tp int) (int64, error)

func SectionIDRandSelector

func SectionIDRandSelector(id int64) selector.SelectOption

select node by section id: game_id / 10

func SpecificIDSelector

func SpecificIDSelector(id int64) selector.SelectOption

select node by specific game_id

Types

type CacheDBLoadCB

type CacheDBLoadCB func(interface{})

type CacheLoader

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

func NewCacheLoader

func NewCacheLoader(ctx context.Context, coll *mongo.Collection, docField string, newFunc CacheObjectNewFunc, dbCB CacheDBLoadCB) *CacheLoader

func (*CacheLoader) Delete

func (c *CacheLoader) Delete(key interface{})

delete cache, stop expire timer

func (*CacheLoader) Load

func (c *CacheLoader) Load(key interface{}) CacheObjector

get cache object, if not hit, load from database

func (*CacheLoader) LoadFromDB

func (c *CacheLoader) LoadFromDB(key interface{}) CacheObjector

only load from database, usually you should only use CacheLoader.Load()

func (*CacheLoader) LoadFromMemory

func (c *CacheLoader) LoadFromMemory(key interface{}) CacheObjector

only load from memory, usually you should only use CacheLoader.Load()

func (*CacheLoader) PureLoadFromDB

func (c *CacheLoader) PureLoadFromDB(key interface{}) []CacheObjector

func (*CacheLoader) Store

func (c *CacheLoader) Store(obj interface{})

save cache object and begin count down timer

type CacheObjectNewFunc

type CacheObjectNewFunc func() interface{}

type CacheObjector

type CacheObjector interface {
	GetObjID() interface{}
	GetExpire() *time.Timer
	ResetExpire()
	StopExpire()
}

type Snowflakes

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

type WaitGroupWrapper

type WaitGroupWrapper struct {
	sync.WaitGroup
}

func (*WaitGroupWrapper) Wrap

func (w *WaitGroupWrapper) Wrap(cb func())

Jump to

Keyboard shortcuts

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