snowflakeid

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 5 Imported by: 0

README

Snowflake id

GoDoc Widget Build Status codecov Go Report Card

A distributed unique ID generator inspired by Twitter's Snowflake.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidSystemClock = errors.New("invalid system clock")
)

Functions

This section is empty.

Types

type Snowflake

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

func NewSnowflake

func NewSnowflake(workerID uint32) (*Snowflake, error)

func (*Snowflake) ID

func (sf *Snowflake) ID() (uint64, error)

func (*Snowflake) WorkerID

func (sf *Snowflake) WorkerID() uint32

type SnowflakeFactory

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

func NewSnowflakeFactory

func NewSnowflakeFactory(bitLenWorkerID, bitLenSequence, gapMs uint, startTime time.Time) *SnowflakeFactory

func (*SnowflakeFactory) BuildID

func (f *SnowflakeFactory) BuildID(workerID uint32, elapsedTime uint64, sequence uint32) (uint64, error)

func (*SnowflakeFactory) CurrentElapsedTime

func (f *SnowflakeFactory) CurrentElapsedTime() uint64

func (*SnowflakeFactory) FlakeTimestamp

func (f *SnowflakeFactory) FlakeTimestamp(t time.Time) uint64

func (*SnowflakeFactory) MaskSequence

func (f *SnowflakeFactory) MaskSequence(sequence uint32) uint32

func (*SnowflakeFactory) MaxSequence

func (f *SnowflakeFactory) MaxSequence() uint32

func (*SnowflakeFactory) MaxTime

func (f *SnowflakeFactory) MaxTime() time.Time

func (*SnowflakeFactory) MaxWorkerID

func (f *SnowflakeFactory) MaxWorkerID() uint32

func (*SnowflakeFactory) NewSnowflake

func (f *SnowflakeFactory) NewSnowflake(workerID uint32) (*Snowflake, error)

func (*SnowflakeFactory) SleepTime

func (f *SnowflakeFactory) SleepTime(overtime time.Duration) time.Duration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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