snowflake

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: MIT Imports: 6 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrGlobalIDBadVal = errors.New("globalID must be a number between (inclusive) 0 and 1023")

ErrGlobalIDBadVal means that the global machine id value wasn't properly set.

Functions

func GlobalMachineID

func GlobalMachineID() int

GlobalMachineID returns the global machine id. This number is limited to a number between 0 and 1023 inclusive.

func SetGlobalMachineID

func SetGlobalMachineID(id int) error

SetGlobalMachineID returns the global machine id. This number is limited to a number between 0 and 1023 inclusive.

Types

type IDGenerator

type IDGenerator struct {
	Generator *snowflake.Generator
}

IDGenerator holds the ID generator.

func NewDefaultIDGenerator

func NewDefaultIDGenerator() *IDGenerator

NewDefaultIDGenerator returns an *IDGenerator that uses the currently set global machine ID. If you change the global machine id, it will not change the id in any generators that have already been created.

func NewIDGenerator

func NewIDGenerator(opts ...IDGeneratorOp) *IDGenerator

NewIDGenerator returns a new IDGenerator. Optionally you can use an IDGeneratorOp. to use a specific Generator

func (*IDGenerator) ID

func (g *IDGenerator) ID() platform2.ID

ID returns the next platform.ID from an IDGenerator.

type IDGeneratorOp

type IDGeneratorOp func(*IDGenerator)

IDGeneratorOp is an option for an IDGenerator.

func WithMachineID

func WithMachineID(machineID int) IDGeneratorOp

WithMachineID uses the low 12 bits of machineID to set the machine ID for the snowflake ID.

Jump to

Keyboard shortcuts

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