Documentation
¶
Overview ¶
Package ids generates time-sortable, globally-unique identifiers (UUIDv7): a 48-bit millisecond timestamp followed by randomness. They sort by creation time, so inserts land at the tail of a database index (tight pages, high cache hit-rate) and they never collide across instances - which matters once records sync across a fleet.
Time and entropy are injectable, so a replay can reproduce the exact same IDs deterministically; the package default uses the system clock and crypto/rand.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator produces UUIDv7 identifiers from an injectable clock and entropy source. The zero value is not usable; construct one with NewGenerator. It is safe for concurrent use.
func NewGenerator ¶
NewGenerator returns a Generator, defaulting to the system clock and crypto/rand.
func (*Generator) Token ¶
Token returns an opaque, cryptographically-random secret with nBytes of entropy, URL-safe base64 without padding. Unlike New, it carries no timestamp and is not an identifier: it is a bearer secret (an API token, say), so it is all entropy and reveals nothing about when it was made. A non-positive nBytes uses 256 bits. The entropy comes from the generator's source, so a deterministic source reproduces the token for a replay just as it does for an ID.