uuid

package module
v0.0.0-...-23bc856 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2017 License: GPL-3.0 Imports: 7 Imported by: 22

README

UUID

UUID (Universally Unique Identifier) is a simple package that implements V4 of the UUID specification.

It also aims to make very basic assumptions of how a empty UUID behaves when used for verifying and checking for equality.


There are few methods for creating a UUID, with or without a random, because there are some environments that can not depend on the basic global random in the standard library. Locking when generating a lot of ids can cause various issues and identify themselves when using -race.

id, err := uuid.New()
if err != nil {
  panic(err)
}
fmt.Println(id.String())

Documentation

Index

Constants

View Source
const (
	// EncodedSize is the length of the text of the encoded UUID
	EncodedSize = 36
)

Variables

View Source
var (
	// Empty UUID is a UUID that is considered empty.
	Empty = UUID([EncodedSize]byte{})
)

Functions

This section is empty.

Types

type UUID

type UUID [EncodedSize]byte

UUID represents identifiers for content, resources and users

func MustNew

func MustNew() UUID

MustNew create a UUID or panics on error

func MustNewWithRand

func MustNewWithRand(rnd *rand.Rand) UUID

MustNewWithRand create a UUID or panics on error

func MustParse

func MustParse(id string) UUID

MustParse parses the uuid or panics

func New

func New() (UUID, error)

New generates a UUID from a random UUID source

func NewWithRand

func NewWithRand(rnd *rand.Rand) (UUID, error)

NewWithRand generates a UUID from a random UUID source

func Parse

func Parse(id string) (UUID, error)

Parse attempts to parse an id and return a UUID, or returns an error on failure.

func ParseBytes

func ParseBytes(b []byte) (UUID, error)

ParseBytes attempts to parse an id and return a UUID, or returns an error on failure.

func (UUID) Bytes

func (u UUID) Bytes() []byte

Bytes returns a series of bytes for the UUID

func (UUID) Equals

func (u UUID) Equals(id UUID) bool

Equals checks that UUID equate to each other.

func (UUID) Generate

func (UUID) Generate(r *rand.Rand, size int) reflect.Value

Generate allows UUID to be used within quickcheck scenarios.

func (UUID) MarshalJSON

func (u UUID) MarshalJSON() ([]byte, error)

MarshalJSON converts a UUID into a serialisable json format

func (UUID) String

func (u UUID) String() string

func (*UUID) UnmarshalJSON

func (u *UUID) UnmarshalJSON(b []byte) error

UnmarshalJSON unserialises the json format and converts it into a UUID

func (UUID) Zero

func (u UUID) Zero() bool

Zero returns if the the UUID is zero or not

Jump to

Keyboard shortcuts

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