identifier

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AtomicGenerator

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

Thread-safe ID generator. Can generate 2^22 (or 4 194 304) locally unique IDs per millisecond, before it wraps around and starts generating duplicates.

func NewAtomicGenerator

func NewAtomicGenerator() AtomicGenerator

Create an atomic ID generator. The generator is thread-safe.

func (*AtomicGenerator) ID

func (g *AtomicGenerator) ID() ID

func (*AtomicGenerator) IDFromTime

func (g *AtomicGenerator) IDFromTime(ts time.Time) ID

type Generator

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

Non-thread-safe ID generator. Can generate 2^22 (or 4 194 304) locally unique IDs per millisecond, before it wraps around and starts generating duplicates.

func NewGenerator

func NewGenerator() Generator

Create an ID generator. The generator is NOT thread-safe.

func (*Generator) ID

func (g *Generator) ID() (id ID)

func (*Generator) IDFromTime

func (g *Generator) IDFromTime(ts time.Time) (id ID)

type ID

type ID uint64

32 bits unix seconds + 32 bits sequence (where first 10 bits are milliseconds)

func Generate

func Generate() ID

Atomically generates the next ID based on current time. Thread-safe.

func IDFromString

func IDFromString(str string) (id ID, err error)

func IDFromTime

func IDFromTime(ts time.Time) ID

Atomically generates the next ID based on provided timestamp. Thread-safe.

func (ID) AppendBinary

func (id ID) AppendBinary(b []byte) ([]byte, error)

AppendBinary implements internal.BinaryAppender.

func (ID) AppendText

func (id ID) AppendText(b []byte) ([]byte, error)

AppendBinary implements internal.TextAppender.

func (ID) Seq

func (id ID) Seq() uint32

Extracts sequence number (last 22 bits)

func (ID) String

func (id ID) String() string

func (ID) Time

func (id ID) Time() time.Time

Converts ID to time.Time

func (ID) Uint64

func (id ID) Uint64() uint64

func (ID) Unix

func (id ID) Unix() uint32

Unix timestamp in seconds precision

Jump to

Keyboard shortcuts

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