Documentation ¶
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 ¶
Types ¶
type UUID ¶
type UUID [16]byte
A UUID representation compliant with specification in RFC 4122 document.
func NewV4 ¶
NewV4 will generate a random UUID in the version 4 format.
Example ¶
package main import ( "fmt" "github.com/pschlump/uuid" ) func main() { u4, err := uuid.NewV4() if err != nil { fmt.Println("error:", err) return } fmt.Printf("%s\n", u4) }
Output:
func NewV5 ¶
NewV5 will generate a UUID based on the SHA-1 hash of a namespace identifier and a name.
Example ¶
package main import ( "fmt" "github.com/pschlump/uuid" ) func main() { u5, err := uuid.NewV5(uuid.NamespaceURL, []byte("nu7hat.ch")) if err != nil { fmt.Printf("Error: %s\n", err) return } fmt.Printf("%s\n", 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 ¶
package main import ( "fmt" "github.com/pschlump/uuid" ) func main() { u, err := uuid.ParseHex("6ba7b810-9dad-11d1-80b4-00c04fd430c8") if err != nil { fmt.Printf("Error: %s\n", err) return } fmt.Printf("%s\n", u) }
Output:
Click to show internal directories.
Click to hide internal directories.