Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
SetGlobalMachineID returns the global machine id. This number is limited to a number between 0 and 1023 inclusive.
Types ¶
type IDGenerator ¶
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() platform.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.