internal

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

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

func NewFactory

func NewFactory(unit int, base time.Time, bits ...int) *Factory

NewFactory creates a snowflake id factory

requirements: 1. MUST generate more than 10 sfids per second 2. MUST be able to generate continuously for 10 years or longer

The `unit` helps mitigate clock rollback to some extent. When the system clock moves backward within the `unit` range, the computed factory gap remains consistent, avoiding conflicts.

func (*Factory) Build

func (f *Factory) Build(worker, seq uint32, gap int64) int64

func (*Factory) Elapsed

func (f *Factory) Elapsed() int64

Elapsed returns units from base to t

func (*Factory) Gap0

func (f *Factory) Gap0() int64

func (*Factory) Gaps

func (f *Factory) Gaps(t time.Time) int64

func (*Factory) Mask

func (f *Factory) Mask(seq uint32) uint32

func (*Factory) New

func (f *Factory) New(wid uint32) *Snowflake

func (*Factory) Next

func (f *Factory) Next(n int64) int64

func (*Factory) SeqBits

func (f *Factory) SeqBits() int

func (*Factory) String

func (f *Factory) String() string

func (*Factory) Tag

func (f *Factory) Tag() string

func (*Factory) Unit

func (f *Factory) Unit() int

func (*Factory) WorkerBits

func (f *Factory) WorkerBits() int

type Snowflake

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

func NewSnowflake

func NewSnowflake(worker uint32, unit int, base time.Time, w, s int) *Snowflake

func (*Snowflake) ID

func (s *Snowflake) ID() int64

func (*Snowflake) Tag

func (s *Snowflake) Tag() string

func (*Snowflake) WorkerID

func (s *Snowflake) WorkerID() uint32

Jump to

Keyboard shortcuts

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