snowflake

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EpochBegin     = int64(1704067200000) // 2024-01-01T00:00:00Z
	SeqShift       = 0
	SeqMask        = uint64(0xFFF)
	MachineIDShift = 12
	MachineIDMask  = uint64(0x3FF000)
	TimestampShift = 22
)

Variables

View Source
var DefaultGenerator = &Generator{}

Functions

This section is empty.

Types

type Generator

type Generator struct {
	MachineID uint32
	Sequence  uint32
}

func (*Generator) Next

func (g *Generator) Next() ID

func (*Generator) NextAt

func (g *Generator) NextAt(t time.Time) ID

func (*Generator) NextAtUnixMilli

func (g *Generator) NextAtUnixMilli(t int64) ID

type ID

type ID uint64

func From

func From(value any) ID

func FromParts

func FromParts(machineID uint32, seq uint32, unixMilli int64) ID

func New

func New() ID

func Zero

func Zero() ID

func (ID) IsZero

func (i ID) IsZero() bool

func (ID) Lowerbound

func (i ID) Lowerbound() ID

func (ID) MachineID

func (i ID) MachineID() uint32

func (ID) MarshalJSON

func (i ID) MarshalJSON() (res []byte, e error)

func (ID) MarshalText

func (i ID) MarshalText() (res []byte, e error)

func (ID) Sequence

func (i ID) Sequence() uint32

func (ID) String

func (i ID) String() string

func (ID) Timestamp

func (i ID) Timestamp() time.Time

func (ID) ToSlice

func (i ID) ToSlice() []byte

func (*ID) UnmarshalJSON

func (i *ID) UnmarshalJSON(data []byte) error

func (*ID) UnmarshalText

func (i *ID) UnmarshalText(data []byte) error

func (ID) Upperbound

func (i ID) Upperbound() ID

func (ID) Valid

func (i ID) Valid() bool

Jump to

Keyboard shortcuts

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