snowflake

package
v0.17.1-0...-36a5d2c Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInitial = errors.New("lal.snowflake: initial error")
	ErrGen     = errors.New("lal.snowflake: gen error")
)

Functions

This section is empty.

Types

type ModOption

type ModOption func(option *Option)

type Node

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

func New

func New(dataCenterID int, workerID int, modOptions ...ModOption) (*Node, error)

dataCenterID 和 workerID 的取值范围取决于 DataCenterIDBits 和 WorkerIDBits 假设 DataCenterIDBits 为 5,则 dataCenterID 取值范围为 [0, 32]

func (*Node) Gen

func (n *Node) Gen(nowUnixMSec ...int64) (int64, error)

type Option

type Option struct {
	DataCenterIDBits int   // 数据中心编号字段在所生成 ID 所占的位数,取值范围见 validate 函数
	WorkerIDBits     int   // 节点编号
	SequenceBits     int   // 递增序列
	Twepoch          int64 // 基准时间点
	AlwaysPositive   bool  // 是否只生成正数 ID,如果是,则时间戳所占位数会减少1位
}

Jump to

Keyboard shortcuts

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