snowflake

package
v0.30.49 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 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(nowUnixMs ...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