Documentation ¶
Overview ¶
Package flake manages IDs very similar to snowflake IDs used by Twitter and others.
Index ¶
- Constants
- Variables
- func TimeAt(ms Millis) time.Time
- type Gen
- type ID
- func (v *ID) DecodeMsgpack(dec *msgpack.Decoder) error
- func (v ID) EncodeMsgpack(enc *msgpack.Encoder) error
- func (id ID) IsZero() bool
- func (id ID) LogValue() slog.Value
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) MarshalText() ([]byte, error)
- func (id ID) Millis() Millis
- func (id ID) MsFirst() ID
- func (id ID) MsLast() ID
- func (id ID) Node() uint64
- func (id ID) Seq() uint64
- func (id *ID) Set(s string) (err error)
- func (id ID) String() string
- func (id ID) StringBytes(quote byte) []byte
- func (id ID) Time() time.Time
- func (id *ID) UnmarshalJSON(input []byte) error
- func (id *ID) UnmarshalText(b []byte) (err error)
- type IDable
- type Memento
- type Millis
- type Newer
Constants ¶
View Source
const ( MaxNode uint64 = nodeMask MaxSeq uint64 = seqMask )
View Source
const EpochMs uint64 = 1577836800_000
EpochMs is the Unix millisecond timestamp corresponding to 0 flake.Millis — Jan 1, 2020 GMT (aka the start of flake epoch).
Variables ¶
View Source
var ErrInvalid = errors.New("invalid flake")
Functions ¶
Types ¶
type ID ¶
type ID uint64
ID has 40 time bits (in ms), 8 node bits, 16 sequence bits.
func ParseBytes ¶
func (*ID) DecodeMsgpack ¶
func (ID) EncodeMsgpack ¶
func (ID) MarshalJSON ¶
func (ID) MarshalText ¶
func (ID) StringBytes ¶
func (*ID) UnmarshalJSON ¶
func (*ID) UnmarshalText ¶
type IDable ¶ added in v0.3.0
type IDable interface {
FlakeID() ID
}
IDable is implemented by anyone carrying ID as a primary identifier.
Click to show internal directories.
Click to hide internal directories.