Documentation ¶ Index ¶ Constants func Decompose(id uint64) map[string]uint64 func IpToUint16(ip net.IP) (uint16, error) func LocalIpToUint16() (uint16, error) type Generator func NewSnowflake(startTime time.Time, nodeID uint16) Generator type Snowflake func (s *Snowflake) NextID() (uint64, error) Examples ¶ NewSnowflake Constants ¶ View Source const ( TimeBit = 39 NodeBit = 16 SequenceBit = 8 ) Variables ¶ This section is empty. Functions ¶ func Decompose ¶ func Decompose(id uint64) map[string]uint64 Decompose 根据id分解为mapping包含这组数据的所有信息 func IpToUint16 ¶ func IpToUint16(ip net.IP) (uint16, error) IpToUint16 将IP地址转化为uint16 func LocalIpToUint16 ¶ func LocalIpToUint16() (uint16, error) LocalIpToUint16 本地IP转化为uint16 Types ¶ type Generator ¶ type Generator interface { // NextID 获取下一个ID NextID() (uint64, error) } Generator 发号器 func NewSnowflake ¶ func NewSnowflake(startTime time.Time, nodeID uint16) Generator NewSnowflake 初始化 StartTime 起始时间 NodeID 服务器ID Example ¶ // 生成对象 generate := NewSnowflake(time.Now(), 1) nid, err := generate.NextID() if err != nil { // 处理错误 } _ = nid Output: type Snowflake ¶ type Snowflake struct { // 互斥锁 sync.Mutex // contains filtered or unexported fields } Snowflake is a distributed unique ID generator. func (*Snowflake) NextID ¶ func (s *Snowflake) NextID() (uint64, error) NextID 获取下一个ID Source Files ¶ View all Source files generator.go snowflake.go Click to show internal directories. Click to hide internal directories.