uuid

package module
v0.0.0-...-fa4f697 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2015 License: MIT Imports: 10 Imported by: 0

README

Yet Another Go UUID Generator

Because there can never be too many uuid generators or uuid types.

Usage

import "github.com/jsipprell/go-uuid"
import "fmt"

func main() {
  var id uuid.UUID

  id = uuid.New()
  fmt.Printf("first uuid is %v\n",id)

  id = uuid.New()
  fmt.Printf("second uuid is %v\n",id)

  id = uuid.New()
  fmt.Printf("third uuid is %v\n",id)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUUIDInvalidEncode = errors.New("uuid: invalided encoded UUID")
)

The only error returned by this package, indicating an attempt to call uuid.Decode() with a string that doesn't appear to be fully formed UUID (or cannot be massaged into one).

Functions

func IsEncoded

func IsEncoded(s string) bool

Returns true if a sring appears to be a hex enooded uuid. Only the first 36 characters of the string are examined, and must consisten of entirely upper or lowercase hexidecimal plus optional hyphens.

func IsZero

func IsZero(u UUID) bool

Returns true if a given uuid is not nil and non-zero.

Types

type UUID

type UUID interface {
	// Exposed interface to a uuid, a 128-bit opaque unique identifier value
	// stored internally as two unsigned 64-bit integers.
	fmt.Stringer
	// UUIDs support the fmt.Stringer interface, as follows:
	//
	// String() Returns a string conversion of the uuid which can be decoded
	// with uuid.Decode(). The string represenation takes the format:
	//
	// HHHHHHHH-HHHH-HHHH-HHHH-HHHHHHHHHHHH
	//
	// Where H represents a lower-case hexidecimal character.
	//
	// For zero-value uuids, String() always return ""
	Bytes() []byte
	// Return a slice of bytes representing the uuid. If the uuid is
	// zero this will return nil.
	Array() [16]byte
	// Return an [16]byte array representing the uuid. If the uuid is
	// zero this will return a 16 byte array filled with zeros.
	Uint64() []uint64
	// Return the uuid as a slice of uint64s. If the uuid is zero this
	// nil.
	IsZero() bool
	// Return true if the uuid is empty and contains no value.
	Equals(UUID) bool
	// Returns true if two uuids are an exact byte // match (internally).
	Len() int
}

func Decode

func Decode(s string) (UUID, error)

Decode a uuid from a string representation. The representation must contains at least 32 hexidecimal characters plus optional (and ignored) hyphens.

func FromArray

func FromArray(a [16]byte) UUID

Returns a UUID from a 16 byte binary represenation of the uuid (available via .Array() or .Bytes())

func New

func New() UUID

Returns a new uuid. The first uuid generated is created using a psuedo-random generator and a seed based on package initialization time. Subsequent uuids are generated as offsets of this initial uuid using a psuedo-random offset also computed at initialization time. For more random uuids, use NewRandom(). New() uses a small queue, is more optimized than NewRandom() and parallelizes the generator

func NewRandom

func NewRandom() UUID

Returns a new psuedo-randomly generated uuid based on a seed computed from the system time at package initialization. Psuedo-random uuid generation is more cpu intensivev and is not optimized for extreme use cases. Normally, one need only use New() to create new uuids.

Jump to

Keyboard shortcuts

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