Documentation
¶
Overview ¶
Package uuid provides support for generating and manipulating UUIDs.
See RFC 9562 for details.
Random components of new UUIDs are generated with a cryptographically secure random number generator.
UUIDs may be generated using various algorithms. The New function returns a new UUID generated using an algorithm suitable for most purposes.
Index ¶
Constants ¶
const UUIDLen = 36 // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Length of a canonical UUID string.
Variables ¶
var ErrInvalid = errors.New("uuid: invalid uuid")
Functions ¶
This section is empty.
Types ¶
type UUID ¶
type UUID struct {
Value [16]byte
}
A UUID is a Universally Unique Identifier as specified in RFC 9562.
UUIDs are comparable, such as with the == operator.
func Max ¶
func Max() UUID
Max returns the Max UUID ffffffff-ffff-ffff-ffff-ffffffffffff.
The Max UUID is defined in Section 5.10 of RFC 9562.
func MustParse ¶
MustParse returns the UUID represented by s.
It panics if s is not a valid string representation of a UUID as defined by Parse.
func New ¶
func New() UUID
New returns a new UUID.
Programs which do not have a need for a specific UUID generation algorithm should use New. At this time, New is equivalent to NewV4.
func NewV4 ¶
func NewV4() UUID
NewV4 returns a new version 4 UUID.
Version 4 UUIDs contain 122 bits of random data.
func NewV7 ¶
func NewV7() UUID
NewV7 returns a new version 7 UUID.
Version 7 UUIDs contain a timestamp in the most significant 48 bits, and at least 62 bits of random data.
func Nil ¶
func Nil() UUID
Nil returns the Nil UUID 00000000-0000-0000-0000-000000000000.
The Nil UUID is defined in Section 5.9 of RFC 9562. Note that this is not the same as the Go value nil.
func Parse ¶
Parse returns the UUID represented by s.
It accepts strings in the following forms:
f81d4fae-7dec-11d0-a765-00a0c91e6bf6
{f81d4fae-7dec-11d0-a765-00a0c91e6bf6}
urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6
f81d4fae7dec11d0a76500a0c91e6bf6
Alphabetic characters in the hexadecimal digits may be any case.
func (UUID) AppendText ¶
AppendText implements the encoding.TextAppender interface. The encoding is the same as returned by UUID.String. Requires at least UUIDLen bytes of spare capacity in buf. Always returns a nil error.
func (UUID) Compare ¶
Compare compares the UUID u with v. If u is before v, it returns -1. If u is after v, it returns +1. If they are the same, it returns 0.
Compare uses the big-endian byte order defined in Section 6.11 of RFC 9562 for sorting.
func (UUID) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. The encoding is the same as returned by UUID.String buf length must be at least UUIDLen bytes.
func (UUID) String ¶
String returns the string representation of u. It uses the lowercase hex-and-dash representation defined in RFC 9562. buf length must be at least UUIDLen bytes.
func (*UUID) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The UUID is expected in a form accepted by Parse.