snowflakeGo

package module
v0.0.0-...-4417e24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

README

snowflake-Go

the twitter/snowflake in Go

Documentation

Index

Constants

View Source
const (
	//开始的时间戳
	START_TIMESTAMP int64 = 1529573798
	//每一部分占用的位数
	SEQUENCE_BIT    uint = 12 //序列号占用的位数
	MACHINE_BIT     uint = 5  //机器标识占用的位数
	DATA_CENTER_BIT uint = 5  //数据中心占用的位数

	//每一部分的最大值
	MAX_MACHINE_NUM     = int64(-1) ^ (int64(-1) << MACHINE_BIT)
	MAX_DATA_CENTER_NUM = int64(-1) ^ (int64(-1) << DATA_CENTER_BIT)
	SEQUENCEMASK        = int64(-1) ^ (int64(-1) << SEQUENCE_BIT)
	//每一部分向左的位移
	MACHINE_LEFT     = SEQUENCE_BIT
	DATA_CENTER_LEFT = SEQUENCE_BIT + MACHINE_BIT
	TIMESTAMP_LEFT   = DATA_CENTER_BIT + MACHINE_BIT + SEQUENCE_BIT
)

Variables

This section is empty.

Functions

This section is empty.

Types

type SnowFlake

type SnowFlake struct {
	// contains filtered or unexported fields
}

func New

func New(dataCenterId int64, machineId int64) (*SnowFlake, error)

func (*SnowFlake) NextId

func (s *SnowFlake) NextId() int64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL