Documentation ¶
Overview ¶
Package snow2 provides a very simple Twitter snowflake generator and parser.
Index ¶
Constants ¶
View Source
const ( // NodeBits holds the number of bits to use for Node // Remember, you have a total 22 bits to share between Node/Step NodeBits uint8 = 10 // StepBits holds the number of bits to use for Step // Remember, you have a total 22 bits to share between Node/Step StepBits uint8 = 12 )
Variables ¶
View Source
var Default, _ = NewNode()
View Source
var Node12, _ = NewNode(WithEpochAdd(97656251), WithNodeBits(2), WithStepBits(8), WithTimeRound(time.Second))
Node12 每秒可以生成 256 个,可以有 4 个节点,可以使用 27.8 年,计算过程,见 cid_test.go 97656251 = 100000000000 >> 10 + 1
View Source
var NodeUint32, _ = NewNode(WithNodeBits(0), WithStepBits(3), WithTimeRound(time.Second))
NodeUint32 creates and returns a unique snowflake ID for uint32 CAUTION: only for low frequency usages,低频使用场景. 每秒可以生成 2^3 = 8 个,可以有 1 个节点,可以使用 17 年 timestamp(29) + node(0) + step(3), 可用 2^29/60/60/24/365 ≈ 17 年 max uint32 is 4294967295 (0b11111111_11111111_11111111_11111111)
Functions ¶
Types ¶
type ConfigFn ¶
type ConfigFn func(*Config)
func WithEpochAdd ¶
func WithNodeBits ¶
func WithNodeID ¶
func WithStepBits ¶
func WithTimeRound ¶
Click to show internal directories.
Click to hide internal directories.