uuid

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SecondsBits  = 32 // 时间戳所占位数
	NodeIDBits   = 12 // 节点ID位数
	SequenceBits = 20 // 序列号

	MaxSeconds  = 1<<32 - 1 // 最大时间戳
	MaxNodeID   = 1<<10 - 1 // 最大节点ID
	MaxSequence = 1<<22 - 1 // 最大序列号

	SecondsMask  = 0xFFFFFFFF00000000 // 时间戳掩码
	SecondsShift = 32                 // 时间戳移位

	NodeIDMask  = 0x00000000FFF00000 // 节点ID掩码
	NodeIDShift = 20                 // 节点ID移位

	SequenceMask  = 0x00000000000FFFFF // 序号掩码
	SequenceShift = 0                  // 序号移位

	CustomEpoch = 1640966400 // 开始时间 2022-01-01 00:00:00 UTC
)

Variables

This section is empty.

Functions

func Decode

func Decode(uuid uint64) (int64, uint16, uint32)

func Encode

func Encode(seconds, node, seq uint64) (uuid uint64)

func GetGuid

func GetGuid() uint64

func GetUuid

func GetUuid() string

func Init

func Init(nodeID uint16)

Types

type Snowflake

type Snowflake struct {
	// contains filtered or unexported fields
}
var Generator *Snowflake

func NewSnowflake

func NewSnowflake(nodeID uint16) *Snowflake

func (*Snowflake) Generate

func (sf *Snowflake) Generate() uint64

生成一个UUID,当时间戳位溢出时会panic 其次当系统时钟回拨时会循环等待系统时钟回到上次生成时间之后

Jump to

Keyboard shortcuts

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