uuid

package
v0.0.68 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2015 License: Apache-2.0, MIT Imports: 8 Imported by: 0

README

Pure Go UUID implementation

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.

Installation

Use the go tool:

$ go get github.com/nu7hatch/gouuid

Usage

See documentation and examples for more information.

Copyright (C) 2011 by Krzysztof Kowalik chris@nu7hat.ch. See COPYING file for details.

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 NewV3

func NewV3(ns *UUID, name []byte) (u *UUID, err error)

Generate a UUID based on the MD5 hash of a namespace identifier and a name.

func NewV4

func NewV4() (u *UUID, err error)

Generate a random UUID.

Example
u4, err := uuid.NewV4()
if err != nil {
	fmt.Println("error:", err)
	return
}
fmt.Println(u4)
Output:

func NewV5

func NewV5(ns *UUID, name []byte) (u *UUID, err error)

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 Parse

func Parse(b []byte) (u *UUID, err error)

Parse creates a UUID object from given bytes slice.

func ParseHex

func ParseHex(s string) (u *UUID, err error)

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:

func (*UUID) String

func (u *UUID) String() string

Returns unparsed version of the generated UUID sequence.

func (*UUID) Variant

func (u *UUID) Variant() byte

Variant returns the UUID Variant, which determines the internal layout of the UUID. This will be one of the constants: RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, RESERVED_FUTURE.

func (*UUID) Version

func (u *UUID) Version() uint

Version returns a version number of the algorithm used to generate the UUID sequence.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL