Package uuid
Overview ▸
Index ▸
type UUID 1.27
A UUID is a Universally Unique Identifier as specified in RFC 9562.
UUIDs are comparable, such as with the == operator.
type UUID [16]byte
func Max 1.27
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 1.27
func MustParse(s string) UUID
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 1.27
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 1.27
func NewV4() UUID
NewV4 returns a new version 4 UUID.
Version 4 UUIDs contain 122 bits of random data.
func NewV7 1.27
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.
NewV7 always returns UUIDs which sort in increasing order, except when the system clock moves backwards.
func Nil 1.27
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 1.27
func Parse(s string) (UUID, error)
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 1.27
func (u UUID) AppendText(b []byte) ([]byte, error)
AppendText implements the encoding.TextAppender interface. The encoding is the same as returned by UUID.String
func (UUID) Compare 1.27
func (u UUID) Compare(v UUID) int
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 1.27
func (u UUID) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface. The encoding is the same as returned by UUID.String
func (UUID) String 1.27
func (u UUID) String() string
String returns the string representation of u.
It uses the lowercase hex-and-dash representation defined in RFC 9562.
func (*UUID) UnmarshalText 1.27
func (u *UUID) UnmarshalText(b []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface. The UUID is expected in a form accepted by Parse.