flake

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = Flaker(&flaker{
	mutex:      &sync.Mutex{},
	machineId:  byte(getLocalIPv4() & machineIdMask),
	epochStart: 1577833200000000000,
})

Default is the default singleton of Flaker with sets the lower 8 bits of the first non loopback IPv4 address (zero if not available) as machine-id and the 1/1/2020 as epoch start (epoch is only needed for sortable IDs).

View Source
var Raw = Flaker(&flaker{
	raw:        true,
	mutex:      &sync.Mutex{},
	machineId:  byte(getLocalIPv4() & machineIdMask),
	epochStart: 1577833200000000000,
})

Functions

This section is empty.

Types

type Flake

type Flake int64

Flake represents a unique 63 bit ID.

func Decode

func Decode(s string) (flake Flake, err error)

Decode decodes a hex, base32 or base64 encoded flake

func FromBytes

func FromBytes(b []byte) (flake Flake, err error)

FromBytes decodes a 8 bit flake instance from bytes

func Next

func Next() Flake

Next is a shorthand for Default.Next()

func NextRaw

func NextRaw() Flake

NextRaw is a shorthand for Raw.Next()

func (Flake) Base32

func (f Flake) Base32() string

Base32 encodes the flake to base32

func (Flake) Base64

func (f Flake) Base64() string

Base64 encodes the flake to base64

func (Flake) Bytes

func (f Flake) Bytes() []byte

Bytes returns the flak as 8 bytes

func (Flake) Hex

func (f Flake) Hex() string

Hex encodes the flake to hex

func (Flake) Int64

func (f Flake) Int64() int64

Int64 returns the flak as raw int64

func (Flake) Uint64

func (f Flake) Uint64() uint64

Uint64 returns the flak as raw uint64

type Flaker

type Flaker interface {
	Next() Flake
	WithMachineId(machineId byte) Flaker
	WithEpochStart(time time.Time) Flaker
}

Flaker is the generator interface.

func WithEpochStart

func WithEpochStart(time time.Time) Flaker

WithEpochStart is a shorthand for Default.WithEpochStart(time)

func WithMachineId

func WithMachineId(machineId byte) Flaker

WithMachineId is a shorthand for Default.WithMachineId(machineId)

Jump to

Keyboard shortcuts

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