snowflake

package
v0.0.0-...-c408d52 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Epoch indicates the unix epoch time for the current implementation in milliseconds.
	Epoch = 1577836800000 // 2020-01-01 00:00:00.000

	// InvalidID indicates the invalid ID.
	InvalidID = 0
)

Variables

This section is empty.

Functions

func MachineID

func MachineID(id uint64) int

MachineID returns the machine identifier field in the given ID.

func Sequence

func Sequence(id uint64) uint64

Sequence returns the sequence number field in the given ID.

func Timestamp

func Timestamp(id uint64) uint64

Timestamp returns the timestamp field (Unix timestamp) in milliseconds of the given ID relative to Epoch.

func TimestampABS

func TimestampABS(id uint64) uint64

TimestampABS returns the absolute timestamp field (Unix timestamp) in milliseconds.

Types

type Snowflake

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

Snowflake implements the Twitter Snowflake ID generator.

func New

func New(machineID int) (*Snowflake, error)

New creates an instance of the Snowflake.

func (*Snowflake) MachineID

func (s *Snowflake) MachineID() int

MachineID returns the machine identifier for the Snowflake instance.

func (*Snowflake) NextID

func (s *Snowflake) NextID() uint64

NextID creates a new ID following the Twitter Snowflake specification.

Jump to

Keyboard shortcuts

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