Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicGenerator ¶ added in v0.1.2
AtomicGenerator define as atomic sequence Resolver, base on standard sync/atomic.
Types ¶
type Generator ¶
type Generator struct { Settings // contains filtered or unexported fields }
Generator a snowflakeID generator
func NewGenerator ¶
NewGenerator create a generator with custom settings
type ID ¶
type ID struct { Timestamp time.Time `json:"timestamp,omitempty"` SinceEpoch uint64 `json:"since_epoch,omitempty"` NodeID uint16 `json:"node_id,omitempty"` Sequence uint16 `json:"sequence,omitempty"` }
ID a snowflake ID
type NodeIDProvider ¶
NodeIDProvider the snowflake Node Generator provider.
type SequenceGenerator ¶ added in v0.1.2
SequenceGenerator the snowflake sequence generator. When use the snowflake algorithm to generate unique ID, make sure:
The sequence-number generated in the same 10 milliseconds of the same node is unique.
Based on this, we create this interface provides following Generator:
AtomicGenerator : base sync/atomic (by default).
type Settings ¶
type Settings struct { // Epoch base time for the timestamp Ref: https://en.wikipedia.org/wiki/Epoch_(computing) Epoch time.Time SequenceGenerator SequenceGenerator NodeIDProvider NodeIDProvider }
Settings snowflake generate settings
Click to show internal directories.
Click to hide internal directories.