Documentation
¶
Index ¶
- type AtomicGenerator
- type Generator
- type ID
- func (id ID) AppendBinary(b []byte) ([]byte, error)
- func (id ID) AppendText(b []byte) ([]byte, error)
- func (id ID) MarshalJSON() (b []byte, err error)
- func (id ID) Seq() uint32
- func (id ID) String() string
- func (id ID) Time() time.Time
- func (id ID) Uint64() uint64
- func (id ID) Unix() uint32
- func (id *ID) UnmarshalJSON(b []byte) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AtomicGenerator ¶
type AtomicGenerator struct {
// contains filtered or unexported fields
}
Thread-safe ID generator. Can generate 2^22 (or 4 194 304) locally unique IDs per millisecond, before it wraps around and starts generating duplicates.
func NewAtomicGenerator ¶
func NewAtomicGenerator() AtomicGenerator
Create an atomic ID generator. The generator is thread-safe.
func (*AtomicGenerator) ID ¶
func (g *AtomicGenerator) ID() ID
func (*AtomicGenerator) IDFromTime ¶
func (g *AtomicGenerator) IDFromTime(ts time.Time) ID
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Non-thread-safe ID generator. Can generate 2^22 (or 4 194 304) locally unique IDs per millisecond, before it wraps around and starts generating duplicates.
func NewGenerator ¶
func NewGenerator() Generator
Create an ID generator. The generator is NOT thread-safe.
type ID ¶
type ID uint64
32 bits unix seconds + 32 bits sequence (where first 10 bits are milliseconds)
func Generate ¶
func Generate() ID
Atomically generates the next ID based on current time. Thread-safe.
func IDFromString ¶
func IDFromTime ¶
Atomically generates the next ID based on provided timestamp. Thread-safe.
func (ID) AppendBinary ¶
AppendBinary implements internal.BinaryAppender.
func (ID) AppendText ¶
AppendBinary implements internal.TextAppender.
func (ID) MarshalJSON ¶ added in v0.6.0
MarshalJSON implements json.Marshaler.
func (*ID) UnmarshalJSON ¶ added in v0.6.0
UnmarshalJSON implements json.Unmarshaler.