flake

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: MIT Imports: 9 Imported by: 2

Documentation

Overview

Package flake manages IDs very similar to snowflake IDs used by Twitter and others.

Index

Constants

View Source
const EpochMs uint64 = 1577836800_000

Bubblehouse epoch starts on Jan 1, 2020 GMT

Variables

View Source
var ErrInvalid = errors.New("invalid flake")

Functions

func TimeAt added in v0.2.1

func TimeAt(ms Millis) time.Time

Types

type Gen

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

func NewGen

func NewGen(mem Memento, node uint64) *Gen

func (*Gen) Memento

func (g *Gen) Memento() Memento

func (*Gen) New

func (g *Gen) New() ID

func (*Gen) NewAt

func (g *Gen) NewAt(now time.Time) ID

type ID

type ID uint64

ID has 40 time bits (in ms), 8 node bits, 16 sequence bits.

func Build

func Build(ms uint64, node uint64, seq uint64) ID

func FirstAt

func FirstAt(tm time.Time) ID

func MinAt

func MinAt(tm time.Time) ID

func Parse

func Parse(s string) (ID, error)

func ParseBytes

func ParseBytes(s []byte) (ID, error)

func (*ID) DecodeMsgpack

func (v *ID) DecodeMsgpack(dec *msgpack.Decoder) error

func (ID) EncodeMsgpack

func (v ID) EncodeMsgpack(enc *msgpack.Encoder) error

func (ID) IsZero

func (id ID) IsZero() bool

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

func (ID) MarshalText

func (id ID) MarshalText() ([]byte, error)

func (ID) Millis added in v0.2.1

func (id ID) Millis() Millis

func (ID) MsFirst

func (id ID) MsFirst() ID

func (ID) MsLast

func (id ID) MsLast() ID

func (ID) Node

func (id ID) Node() uint64

func (ID) Seq

func (id ID) Seq() uint64

func (*ID) Set

func (id *ID) Set(s string) (err error)

func (ID) String

func (id ID) String() string

func (ID) StringBytes

func (id ID) StringBytes(quote byte) []byte

func (ID) Time

func (id ID) Time() time.Time

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(input []byte) error

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(b []byte) (err error)

type IDish added in v0.2.1

type IDish interface {
	FlakeID() ID
}

type Memento

type Memento uint64

type Millis added in v0.2.1

type Millis = uint64

Millis is an alias for uint64 for code clarity.

func MillisAt added in v0.2.1

func MillisAt(tm time.Time) Millis

type Newer added in v0.2.1

type Newer interface {
	NewID() ID
}

Jump to

Keyboard shortcuts

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