uuid

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2015 License: MIT Imports: 8 Imported by: 17

README

Stories in Ready

uuid

golang uuid generator

install

go get github.com/fgrid/uuid

benchmarks

BenchmarkNewV1	 2000000	       725 ns/op
BenchmarkNewV3	 2000000	       746 ns/op
BenchmarkNewV4	 1000000	      1942 ns/op
BenchmarkNewV5	 2000000	       784 ns/op

documentation

badges

status library users dependents views Go Report Card

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// NIL is defined in RFC 4122 section 4.1.7.
	// The nil UUID is special form of UUID that is specified to have all 128 bits set to zero.
	NIL = &UUID{
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	}
	// NameSpaceDNS assume name to be a fully-qualified domain name.
	// Declared in RFC 4122 Appendix C.
	NameSpaceDNS = &UUID{
		0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1,
		0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8,
	}
	// NameSpaceURL assume name to be a URL.
	// Declared in RFC 4122 Appendix C.
	NameSpaceURL = &UUID{
		0x6b, 0xa7, 0xb8, 0x11, 0x9d, 0xad, 0x11, 0xd1,
		0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8,
	}
	// NameSpaceOID assume name to be an ISO OID.
	// Declared in RFC 4122 Appendix C.
	NameSpaceOID = &UUID{
		0x6b, 0xa7, 0xb8, 0x12, 0x9d, 0xad, 0x11, 0xd1,
		0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8,
	}
	// NameSpaceX500 assume name to be a X.500 DN (in DER or a text output format).
	// Declared in RFC 4122 Appendix C.
	NameSpaceX500 = &UUID{
		0x6b, 0xa7, 0xb8, 0x14, 0x9d, 0xad, 0x11, 0xd1,
		0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8,
	}
)

Functions

This section is empty.

Types

type UUID

type UUID [16]byte

The UUID represents Universally Unique IDentifier (which is 128 bit long).

func NewNamespaceUUID

func NewNamespaceUUID(namespace string) *UUID

NewNamespaceUUID creates a namespace UUID by using the namespace name in the NIL name space. This is a different approach as the 4 "standard" namespace UUIDs which are timebased UUIDs (V1).

Example
fmt.Printf("UUID(test):        %s\n", NewNamespaceUUID("test"))
fmt.Printf("UUID(myNameSpace): %s\n", NewNamespaceUUID("myNameSpace"))
Output:

UUID(test):        e8b764da-5fe5-51ed-8af8-c5c6eca28d7a
UUID(myNameSpace): 40e41e4d-01d6-5e36-8c6b-93edcdf1442d

func NewV1

func NewV1() *UUID

NewV1 creates a new UUID with variant 1 as described in RFC 4122. Variant 1 is based on hosts MAC address and actual timestamp (as count of 100-nanosecond intervals since 00:00:00.00, 15 October 1582 (the date of Gregorian reform to the Christian calendar).

func NewV3

func NewV3(namespace *UUID, name []byte) *UUID

NewV3 creates a new UUID with variant 3 as described in RFC 4122. Variant 3 based namespace-uuid and name and MD-5 hash calculation.

func NewV4

func NewV4() *UUID

NewV4 creates a new UUID with variant 4 as described in RFC 4122. Variant 4 based on pure random bytes.

func NewV5

func NewV5(namespaceUUID *UUID, name []byte) *UUID

NewV5 creates a new UUID with variant 5 as described in RFC 4122. Variant 5 based namespace-uuid and name and SHA-1 hash calculation.

func (*UUID) String

func (u *UUID) String() string

String returns the human readable form of the UUID.

func (*UUID) Version

func (u *UUID) Version() int

Version of the UUID represents a kind of subtype specifier.

Jump to

Keyboard shortcuts

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