Documentation
¶
Index ¶
Constants ¶
View Source
const ( Size = 16 V7 byte = 7 )
View Source
const ( VariantNCS = iota VariantRFC4122 VariantMicrosoft VariantFuture )
Variables ¶
View Source
var ErrBigTime = errors.New("uuid: timestamp overflow, cannot generate")
Functions ¶
Types ¶
type UUID ¶
func NewV7 ¶
NewV7 This is an implementation of a UUIDv7-compatible ID generator. The reference used was the latest version of the draft IETF RFC4122bis specification at
https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-14.html
The UUIDv7 bit layout is
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | unix_ts_ms | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | unix_ts_ms | ver | rand_a | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |var| rand_b | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | rand_b | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The fields are to be filled as follows:
- unix_ts_ms: a 48-bit Unix millisecond timestamp.
- ver: the 4-bit literal value 0b0111 (7) denoting the UUID version.
- rand_a: a 12-bit pseudo-random value.
- var: the 2-bit literal value 0b10 (2) denoting the UUID variant.
- rand_b: a 62-bit pseudo-random value.
The specification allows for additional monotonicity guarantees within the millisecond by incrementing the value of rand_b by a random integer of any desired length for additional UUIDs generated within a single timestamp tick. This may become relevant in future. For now, we generate a new 74-bit pseudo-random value for every generated UUID.
Click to show internal directories.
Click to hide internal directories.