ider

package module
v0.0.0-...-e9503d7 Latest Latest
Warning

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

Go to latest
Published: May 6, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

README

ID生成器

使用

# idgener
id := ID()
for i := 1; i <= 1000000; i++ {
	fmt.Printf("ID: %s \n", <-id)
}

# snowflake
id := NewID(1)
for i := 1; i <= 10; i++ {
	fmt.Printf("%d: %d \n", wid, id.Next())
}

Documentation

Index

Constants

View Source
const (
	CWorkerIdBits  = 10 // Num of WorkerId Bits
	CSenquenceBits = 12 // Num of Sequence Bits

	CWorkerIdShift  = 12
	CTimeStampShift = 22

	CSequenceMask = 0xfff // equal as getSequenceMask()
	CMaxWorker    = 0x3ff // equal as getMaxWorkerId()
)

Variables

Functions

func ID

func ID() <-chan string

func ParseId

func ParseId(id int64) (t time.Time, ts int64, workerId int64, seq int64)

ParseId Func: reverse uid to timestamp, workid, seq

Types

type IDGener

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

type IdGen

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

func (*IdGen) Next

func (ig *IdGen) Next() int64

type SnowFlake

type SnowFlake interface {
	Next() int64
}

func NewID

func NewID(workerid int64) SnowFlake

Jump to

Keyboard shortcuts

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