Documentation ¶
Overview ¶
Package idgen is a snowflake id generator
Index ¶
- func ExtractTime(id int64) time.Time
- func NextId() int64
- func SetIdGenerator(options *IdGeneratorOptions)
- type DefaultIdGenerator
- type IIdGenerator
- type ISnowWorker
- type IdGeneratorException
- type IdGeneratorOptions
- type OverCostActionArg
- type SnowWorkerM1
- func (m1 *SnowWorkerM1) BeginOverCostAction(useTimeTick int64)
- func (m1 *SnowWorkerM1) BeginTurnBackAction(useTimeTick int64)
- func (m1 *SnowWorkerM1) CalcId(useTimeTick int64) int64
- func (m1 *SnowWorkerM1) CalcTurnBackId(useTimeTick int64) int64
- func (m1 *SnowWorkerM1) DoGenIdAction(arg *OverCostActionArg)
- func (m1 *SnowWorkerM1) EndOverCostAction(useTimeTick int64)
- func (m1 *SnowWorkerM1) EndTurnBackAction(useTimeTick int64)
- func (m1 *SnowWorkerM1) GetCurrentTimeTick() int64
- func (m1 *SnowWorkerM1) GetNextTimeTick() int64
- func (m1 *SnowWorkerM1) NextId() int64
- func (m1 *SnowWorkerM1) NextNormalId() int64
- func (m1 *SnowWorkerM1) NextOverCostId() int64
- type SnowWorkerM2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractTime ¶ added in v1.3.0
Types ¶
type DefaultIdGenerator ¶
type DefaultIdGenerator struct { Options *IdGeneratorOptions SnowWorker ISnowWorker IdGeneratorException IdGeneratorException }
func NewDefaultIdGenerator ¶
func NewDefaultIdGenerator(options *IdGeneratorOptions) *DefaultIdGenerator
func (DefaultIdGenerator) ExtractTime ¶ added in v1.3.0
func (dig DefaultIdGenerator) ExtractTime(id int64) time.Time
func (DefaultIdGenerator) NewLong ¶
func (dig DefaultIdGenerator) NewLong() int64
type IIdGenerator ¶
type IIdGenerator interface {
NewLong() uint64
}
type ISnowWorker ¶
type ISnowWorker interface {
NextId() int64
}
func NewSnowWorkerM1 ¶
func NewSnowWorkerM1(options *IdGeneratorOptions) ISnowWorker
NewSnowWorkerM1 .
func NewSnowWorkerM2 ¶
func NewSnowWorkerM2(options *IdGeneratorOptions) ISnowWorker
type IdGeneratorException ¶
type IdGeneratorException struct {
// contains filtered or unexported fields
}
func (IdGeneratorException) IdGeneratorException ¶
func (e IdGeneratorException) IdGeneratorException(message ...interface{})
type IdGeneratorOptions ¶
type IdGeneratorOptions struct { Method uint16 // 雪花计算方法,(1-漂移算法|2-传统算法),默认1 BaseTime int64 // 基础时间(ms单位),不能超过当前系统时间 WorkerId uint16 // 机器码,必须由外部设定,最大值 2^WorkerIdBitLength-1 WorkerIdBitLength byte // 机器码位长,默认值6,取值范围 [1, 15](要求:序列数位长+机器码位长不超过22) SeqBitLength byte // 序列数位长,默认值6,取值范围 [3, 21](要求:序列数位长+机器码位长不超过22) MaxSeqNumber uint32 // 最大序列数(含),设置范围 [MinSeqNumber, 2^SeqBitLength-1],默认值0,表示最大序列数取最大值(2^SeqBitLength-1]) MinSeqNumber uint32 // 最小序列数(含),默认值5,取值范围 [5, MaxSeqNumber],每毫秒的前5个序列数对应编号0-4是保留位,其中1-4是时间回拨相应预留位,0是手工新值预留位 TopOverCostCount uint32 // 最大漂移次数(含),默认2000,推荐范围500-10000(与计算能力有关) }
func NewIdGeneratorOptions ¶
func NewIdGeneratorOptions(workerId uint16) *IdGeneratorOptions
type OverCostActionArg ¶
type OverCostActionArg struct { ActionType int32 TimeTick int64 WorkerId uint16 OverCostCountInOneTerm int32 GenCountInOneTerm int32 TermIndex int32 }
func (OverCostActionArg) OverCostActionArg ¶
type SnowWorkerM1 ¶
type SnowWorkerM1 struct { BaseTime int64 // 基础时间 WorkerId uint16 // 机器码 WorkerIdBitLength byte // 机器码位长 SeqBitLength byte // 自增序列数位长 MaxSeqNumber uint32 // 最大序列数(含) MinSeqNumber uint32 // 最小序列数(含) TopOverCostCount uint32 // 最大漂移次数 sync.Mutex // contains filtered or unexported fields }
SnowWorkerM1 .
func (*SnowWorkerM1) BeginOverCostAction ¶
func (m1 *SnowWorkerM1) BeginOverCostAction(useTimeTick int64)
func (*SnowWorkerM1) BeginTurnBackAction ¶
func (m1 *SnowWorkerM1) BeginTurnBackAction(useTimeTick int64)
func (*SnowWorkerM1) CalcId ¶ added in v1.2.1
func (m1 *SnowWorkerM1) CalcId(useTimeTick int64) int64
CalcID .
func (*SnowWorkerM1) CalcTurnBackId ¶ added in v1.2.1
func (m1 *SnowWorkerM1) CalcTurnBackId(useTimeTick int64) int64
CalcTurnBackID .
func (*SnowWorkerM1) DoGenIdAction ¶ added in v1.2.1
func (m1 *SnowWorkerM1) DoGenIdAction(arg *OverCostActionArg)
DoGenIDAction .
func (*SnowWorkerM1) EndOverCostAction ¶
func (m1 *SnowWorkerM1) EndOverCostAction(useTimeTick int64)
func (*SnowWorkerM1) EndTurnBackAction ¶
func (m1 *SnowWorkerM1) EndTurnBackAction(useTimeTick int64)
func (*SnowWorkerM1) GetCurrentTimeTick ¶
func (m1 *SnowWorkerM1) GetCurrentTimeTick() int64
GetCurrentTimeTick .
func (*SnowWorkerM1) GetNextTimeTick ¶
func (m1 *SnowWorkerM1) GetNextTimeTick() int64
GetNextTimeTick .
func (*SnowWorkerM1) NextNormalId ¶ added in v1.2.1
func (m1 *SnowWorkerM1) NextNormalId() int64
NextNormalID .
func (*SnowWorkerM1) NextOverCostId ¶ added in v1.2.1
func (m1 *SnowWorkerM1) NextOverCostId() int64
type SnowWorkerM2 ¶
type SnowWorkerM2 struct {
*SnowWorkerM1
}
func (SnowWorkerM2) NextId ¶ added in v1.2.1
func (m2 SnowWorkerM2) NextId() int64
Click to show internal directories.
Click to hide internal directories.