Documentation ¶
Overview ¶
Package random 雪花算法修改版 0 - 毫秒时间戳(41 bit) - 序列号(12 bit) - 机器 id(10 bit) 0 - 69年 - 4000(每秒 1000 * 4000 个 uuid) - 1000
时间回拨处理: 1 当相差 15 ms 之内时,等待时间追上 2 当超过 15 ms 时,直接替换机器 id
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrSnowflakeWorkerID 无效的 workerID,取值范围 [0, defaultMaxWorkerID] ErrSnowflakeWorkerID = errors.New("bad worker id") // ErrSnowflakeTimeBackward 时间倒退,当前时间比上一次记录的时间还要小 ErrSnowflakeTimeBackward = errors.New("time backward") )
Functions ¶
func NewUUID ¶
func NewUUID() string
NewUUID 全局唯一标识符,12byte
基于时间戳,主机信息,进程 ID 生成,每次调用值加 1,具有原子性
eg: NewUUID() -> 5cb840f90a5dcd71e779ba64
eg: NewUUID() -> 5cb840f90a5dcd71e779ba65
func SetSnowflakeTestTimebackward ¶
func SetSnowflakeTestTimebackward(able bool)
SetSnowflakeTestTimebackward 测试时间回退
Types ¶
type Snowflake ¶
type Snowflake struct {
// contains filtered or unexported fields
}
Snowflake uuid 生成器
func NewBit46Snowflake ¶ added in v0.19.6
NewBit46Snowflake 生成46 bit 的 uint64 workerId: 1-8
func NewSnowflakeBy ¶
func NewSnowflakeBy(workerID int, originTime int64, workerIDBits int, sequenceBits int, nextWorkIDFunc SnowflakeNextWorkIDFunc, backWorkIDFunc SnowflakeBackWorkIDFunc) (*Snowflake, error)
NewSnowflakeBy 创建生成器
func (*Snowflake) SetOriginTime ¶
SetOriginTime 设置起始时间
func (*Snowflake) SetWorkIDFunc ¶
func (snowflake *Snowflake) SetWorkIDFunc(nextWorkIDFunc SnowflakeNextWorkIDFunc, backWorkIDFunc SnowflakeBackWorkIDFunc)
SetWorkIDFunc 设置时间回拨超过 15 ms 后,用于处理 workID 的函数
func (*Snowflake) UnsafeUUID ¶
UnsafeUUID 获取 uuid,非线程安全
type SnowflakeBackWorkIDFunc ¶ added in v0.19.6
SnowflakeBackWorkIDFunc ..
type SnowflakeNextWorkIDFunc ¶ added in v0.19.6
SnowflakeNextWorkIDFunc ..
Click to show internal directories.
Click to hide internal directories.