Documentation
¶
Overview ¶
This package implements a UUID generator and some other functionalities revolving UUIDs. Read in RFC9562 for more info about UUIDs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type UUID ¶
type UUID [16]byte
This represents a 128bit UUID type. Elements of this type can, and should, be compared using the == operator. The zero value of UUID is classified as a Nil UUID according to RFC9562 section 5.9.
func FromBytes ¶
Converts an UUID from a byte slice. The given byte slice should be of length 16, otherwise an error will be returned. Due to this, this function is NOT interchangeable with FromString, a byte slice that represents the string representation of an UUID should be converted with FromString.
func FromString ¶
Converts an UUID from a string format. Note that this function is NOT interchangeable with FromBytes, even considering convertion.
func NewUUIDv7 ¶
func NewUUIDv7() UUID
Generates a new UUID accourding to version 7. It's safe to call this function from multiple goroutines.
The memory layout of a UUIDv7 is as follows:
Unix Timestamp: 48-bit big-endian unsigned number of the Unix Epoch timestamp in milliseconds. Occupies bits 0 through 47, octets 1 through 5.
Version: 4-bit version field, set to 0b0111 (7). Occupies bits 48 through 51, octet 6.
Random A: 12-bit pseudorandom data to provide uniqueness. Occupies bits 52 through 63, octects 6 through 7.
Variant: 2-bit variant field, set to 0b10. Occupies bits 64 through 65, octet 8.
Random B: 62-bit pseudorandom data to provide uniqueness. Occupies bits 66 through 127, octets 8 through 15.
func (UUID) IsNil ¶
Verifies whether the given UUID is the Nil UUID. Not be confused with a nil pointer to an UUID. Equivalent to using == against the zero value of this type.
func (UUID) MarshalJSON ¶
Implements the interface [json.Marshaler] on the UUID type.
func (UUID) String ¶
Implements the interface fmt.Stringer on the UUID type.
func (*UUID) UnmarshalJSON ¶
Implements the interface [json.Unmarshaler] on the UUID type. The given byte slice should be a valid JSON string literal.