Documentation ¶
Overview ¶
Package uuid generates and inspects UUIDs.
UUIDs are based on RFC 4122 and DCE 1.1: Authentication and Security Services.
A UUID is a 16 byte (128 bit) array. UUIDs may be used as keys to maps or compared directly.
Index ¶
- Constants
- func SetRand(r io.Reader)
- type UUID
- func (uuid UUID) MarshalBinary() ([]byte, error)
- func (uuid UUID) MarshalText() ([]byte, error)
- func (uuid UUID) String() string
- func (uuid UUID) URN() string
- func (uuid *UUID) UnmarshalBinary(data []byte) error
- func (uuid *UUID) UnmarshalText(data []byte) error
- func (uuid UUID) Variant() Variant
- func (uuid UUID) Version() Version
- type Variant
- type Version
Constants ¶
const ( Invalid = Variant(iota) // Invalid UUID RFC4122 // The variant specified in RFC4122 Reserved // Reserved, NCS backward compatibility. Microsoft // Reserved, Microsoft Corporation backward compatibility. Future // Reserved for future definition. )
Constants returned by Variant.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type UUID ¶
type UUID [16]byte
A UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC 4122.
func FromBytes ¶
FromBytes creates a new UUID from a byte slice. Returns an error if the slice does not have a length of 16. The bytes are copied from the slice.
func MustParse ¶
MustParse is like Parse but panics if the string cannot be parsed. It simplifies safe initialization of global variables holding compiled UUIDs.
func New ¶
func New() UUID
New creates a new random UUID or panics. New is equivalent to the expression
uuid.Must(uuid.NewRandom())
func NewRandom ¶
NewRandom returns a Random (Version 4) UUID.
The strength of the UUIDs is based on the strength of the crypto/rand package.
A note about uniqueness derived from the UUID Wikipedia entry:
Randomly generated UUIDs have 122 random bits. One's annual risk of being hit by a meteorite is estimated to be one chance in 17 billion, that means the probability is about 0.00000000006 (6 × 10−11), equivalent to the odds of creating a few tens of trillions of UUIDs in a year and having one duplicate.
func Parse ¶
Parse decodes s into a UUID or returns an error. Both the standard UUID forms of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded as well as the Microsoft encoding {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} and the raw hex encoding: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
func ParseBytes ¶
ParseBytes is like Parse, except it parses a byte slice instead of a string.
func (UUID) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler.
func (UUID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (UUID) String ¶
String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx , or "" if uuid is invalid.
func (UUID) URN ¶
URN returns the RFC 2141 URN form of uuid, urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, or "" if uuid is invalid.
func (*UUID) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler.
func (*UUID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.