Documentation
¶
Index ¶
- func ExtractTime(id int64) time.Time
- func ExtractTimeBase36(base36 string) time.Time
- func ExtractTimeBase62(base62 string) time.Time
- func ExtractTimeHex(hex string) time.Time
- func ExtractWorkerId(id int64) int64
- func ExtractWorkerIdBase36(base36 string) int64
- func ExtractWorkerIdBase62(base62 string) int64
- func ExtractWorkerIdHex(hex string) int64
- func NextBase36() string
- func NextBase62() string
- func NextHex() string
- func NextInt() int64
- func NextString() string
- func WithOptions(options *Options)
- func WithOptionsAndWorkerManager(manager WorkerIdManager, options *Options) error
- type DefaultIdGenerator
- type ISnowflake
- type Options
- type ShardedGenerator
- type Snowflake
- func (sw *Snowflake) CalcId(useTimeTick int64) int64
- func (sw *Snowflake) CalcTurnBackId(useTimeTick int64) int64
- func (sw *Snowflake) ExtractTime(id int64) time.Time
- func (sw *Snowflake) ExtractWorkerId(id int64) int64
- func (sw *Snowflake) GetCurrentTimeTick() int64
- func (sw *Snowflake) GetNextTimeTick() int64
- func (sw *Snowflake) NextId() int64
- func (sw *Snowflake) NextNormalId() int64
- func (sw *Snowflake) NextOverCostId() int64
- type SnowflakeLockFree
- type WorkerIdManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractTime ¶
ExtractTime @Description: 提取ID时间 @param id @return time.Time
func ExtractTimeBase36 ¶
func ExtractTimeBase62 ¶
func ExtractTimeHex ¶
func ExtractWorkerId ¶
ExtractWorkerId @Description: 提取工作节点ID @param id @return int64
func ExtractWorkerIdBase36 ¶
func ExtractWorkerIdBase62 ¶
func ExtractWorkerIdHex ¶
func WithOptions ¶
func WithOptions(options *Options)
func WithOptionsAndWorkerManager ¶
func WithOptionsAndWorkerManager(manager WorkerIdManager, options *Options) error
Types ¶
type DefaultIdGenerator ¶
type DefaultIdGenerator struct {
SnowWorker ISnowflake
}
func (DefaultIdGenerator) ExtractTime ¶
func (dig DefaultIdGenerator) ExtractTime(id int64) time.Time
func (DefaultIdGenerator) ExtractWorkerId ¶
func (dig DefaultIdGenerator) ExtractWorkerId(id int64) int64
func (DefaultIdGenerator) NextId ¶
func (dig DefaultIdGenerator) NextId() int64
type ISnowflake ¶
type ISnowflake interface {
NextId() int64
ExtractTime(int64) time.Time
ExtractWorkerId(id int64) int64
}
func NewDefaultIdGenerator ¶
func NewDefaultIdGenerator(options *Options) ISnowflake
func NewShardedGenerator ¶
func NewShardedGenerator(options *Options) ISnowflake
func NewSnowflake ¶
func NewSnowflake(options *Options) ISnowflake
type Options ¶
type Options struct {
BaseTime int64 // 基础时间(ms单位),不能超过当前系统时间
WorkerId int64 // 机器码,最大值 2^WorkerIdBitLength-1
WorkerIdBitLength byte // 机器码位长,默认值4,取值范围 [1~19,f](要求:序列数位长+机器码位长不超过22)
SeqBitLength byte // 序列数位长,默认值6,取值范围 [3~21,22](要求:序列数位长+机器码位长不超过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(与计算能力有关)
ShardedMode bool // 单机高性能模式,默认false,如果开启,WorkerId将被忽略,WorkerIdBitLength用来控制分片量
}
func (*Options) MaxWorkerIdNumber ¶
type ShardedGenerator ¶
type ShardedGenerator struct {
// contains filtered or unexported fields
}
func (*ShardedGenerator) ExtractTime ¶
func (s *ShardedGenerator) ExtractTime(id int64) time.Time
func (*ShardedGenerator) ExtractWorkerId ¶
func (s *ShardedGenerator) ExtractWorkerId(id int64) int64
func (*ShardedGenerator) NextId ¶
func (s *ShardedGenerator) NextId() int64
type Snowflake ¶
func (*Snowflake) CalcTurnBackId ¶
func (*Snowflake) ExtractWorkerId ¶
func (*Snowflake) GetCurrentTimeTick ¶
func (*Snowflake) GetNextTimeTick ¶
func (*Snowflake) NextNormalId ¶
func (*Snowflake) NextOverCostId ¶
type SnowflakeLockFree ¶
type SnowflakeLockFree struct {
}
Click to show internal directories.
Click to hide internal directories.