snowflake

package
v0.0.0-...-98075fd Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2020 License: GPL-3.0 Imports: 5 Imported by: 0

README

snowflake 算法生成uuid

原文:
golang实现的GUID发号器

Documentation

Index

Constants

View Source
const (
	//Poch ( 2017-05-27 16:52:35.250507739 +0800 CST ).UnixNano() / 1e6
	Poch = 1495875155250
	//WorkerIDBits WorkerId所占的位
	WorkerIDBits = uint64(10)
	//SenquenceBits 序列号占的位
	SenquenceBits = uint64(12)
	//WorkerIDShift 参照
	WorkerIDShift = SenquenceBits
	//TimeStampShift 参照
	TimeStampShift = SenquenceBits + WorkerIDBits
	//SequenceMask 最大序列号值 4095(4096个)
	SequenceMask = int64(-1) ^ (int64(-1) << SenquenceBits)
	//MaxWorker 最大客户端标志值 1023(1024个)
	MaxWorker = int64(-1) ^ (int64(-1) << WorkerIDBits)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GUID

type GUID struct {
	sync.Mutex
	//Sequence 序列号
	Sequence int64

	//WorkID
	WorkID int64
	// contains filtered or unexported fields
}

GUID GUID定义

func NewGUID

func NewGUID(workID int64) (*GUID, error)

NewGUID 获取一个GUID对象

func (*GUID) GetIncreaseID

func (g *GUID) GetIncreaseID(ID *uint64) uint64

GetIncreaseID 并发环境下生成一个增长的id,按需设置局部变量或者全局变量

func (*GUID) NextID

func (g *GUID) NextID() (int64, error)

NextID 获取一个GUID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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