Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultConfig 雪花算法默认配置 DefaultConfig = SnowFlakeConfig{ StartTimestamp: 0, TimestampBits: 41, MachineIdBits: 10, SeqBits: 12, } )
Functions ¶
func GetMachineId ¶ added in v1.0.4
func GetMachineId(c SnowFlakeConfig, id int64) (int64, error)
GetMachineId 获取机器码
Types ¶
type SnowFlakeConfig ¶
type SnowFlakeConfig struct { // 起始时间戳,单位为毫秒,默认为0,即1970-01-01 00:00:00.000 StartTimestamp int64 // 时间戳位数,默认为41 TimestampBits uint8 // 机器码位数,默认为10 MachineIdBits uint8 // 序列号位数,默认为12 SeqBits uint8 }
SnowFlakeConfig 雪花
func NewDefaultConfigWithStartTime ¶ added in v1.0.3
func NewDefaultConfigWithStartTime(startTime time.Time) SnowFlakeConfig
NewDefaultConfigWithStartTime 创建一个雪花算法默认配置,并指定起始时间
func (*SnowFlakeConfig) SetStartTime ¶
func (c *SnowFlakeConfig) SetStartTime(startTime time.Time)
SetStartTime 设置起始时间
type SnowflakeError ¶ added in v1.0.5
type SnowflakeError string
const ( BitsSumError SnowflakeError = "the sum of bits error, must be 63" MachineIdIllegal SnowflakeError = "machine id is illegal" TimestampIllegal SnowflakeError = "timestamp is illegal" SeqIllegal SnowflakeError = "sequence is illegal" )
func (SnowflakeError) Error ¶ added in v1.0.5
func (e SnowflakeError) Error() string
type WorkerInterface ¶ added in v1.0.4
func NewWorker ¶
func NewWorker(c SnowFlakeConfig, machineId int64) (WorkerInterface, error)
NewWorker 创建一个雪花算法的工作节点
Click to show internal directories.
Click to hide internal directories.