Documentation ¶
Overview ¶
This package provides immutable UUID structs and the functions NewV3, NewV4, NewV5 and Parse() for generating versions 3, 4 and 5 UUIDs as specified in RFC 4122.
Copyright (C) 2011 by Krzysztof Kowalik <chris@nu7hat.ch>
Index ¶
Examples ¶
Constants ¶
View Source
const ( ReservedNCS byte = 0x80 ReservedRFC4122 byte = 0x40 ReservedMicrosoft byte = 0x20 ReservedFuture byte = 0x00 )
The UUID reserved variants.
Variables ¶
View Source
var (
NamespaceDNS, _ = ParseHex("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
NamespaceURL, _ = ParseHex("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
NamespaceOID, _ = ParseHex("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
NamespaceX500, _ = ParseHex("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
)
The following standard UUIDs are for use with NewV3() or NewV5().
Functions ¶
This section is empty.
Types ¶
type UUID ¶
type UUID [16]byte
A UUID representation compliant with specification in RFC 4122 document.
func NewV4 ¶
Generate a random UUID.
Example ¶
u4, err := uuid.NewV4() if err != nil { fmt.Println("error:", err) return } fmt.Println(u4)
Output:
func NewV5 ¶
Generate a UUID based on the SHA-1 hash of a namespace identifier and a name.
Example ¶
u5, err := uuid.NewV5(uuid.NamespaceURL, []byte("nu7hat.ch")) if err != nil { fmt.Println("error:", err) return } fmt.Println(u5)
Output:
func ParseHex ¶
ParseHex creates a UUID object from given hex string representation. Function accepts UUID string in following formats:
uuid.ParseHex("6ba7b814-9dad-11d1-80b4-00c04fd430c8") uuid.ParseHex("{6ba7b814-9dad-11d1-80b4-00c04fd430c8}") uuid.ParseHex("urn:uuid:6ba7b814-9dad-11d1-80b4-00c04fd430c8")
Example ¶
u, err := uuid.ParseHex("6ba7b810-9dad-11d1-80b4-00c04fd430c8") if err != nil { fmt.Println("error:", err) return } fmt.Println(u)
Output:
Click to show internal directories.
Click to hide internal directories.