Documentation ¶
Overview ¶
Package uuid generates a 128-bit UUID based on Unix time (similar to one of CouchDB's UUID options).
For example:
0505 da61 3800 49RR RRRR RRRR RRRR RRRR ----------------- 7 bytes, unix time in hex microseconds ---------------------- 9 bytes, random data
The benefits of this form of UUID are chronological sortability, which is good for database key usage, and a measure of protection against predictability, since it carries at least 72 bits of entropy (9 x 8b). Note that this doesn't necessarily make it a good choice for cryptographic purposes.
This package defaults to the UUID form without dashes, as they're not particularly useful in this format.
Index ¶
- Constants
- Variables
- func Equal(u1 UUID, u2 UUID) bool
- type UUID
- func (u *UUID) Array() *[UUID_BYTES]byte
- func (u UUID) Bytes() []byte
- func (u *UUID) IsNil() bool
- func (u UUID) MarshalBinary() ([]byte, error)
- func (u UUID) MarshalText() ([]byte, error)
- func (u UUID) String() string
- func (u UUID) ToTime() time.Time
- func (u *UUID) UnmarshalBinary(b []byte) error
- func (u *UUID) UnmarshalText(text []byte) error
Constants ¶
const ( UUID_BYTES = 16 UUID_RANDOM_BYTES = 9 UUID_RANDOM_OFFSET = 7 UUID_STRING_LENGTH = 32 UUID_STRING_LENGTH_WITH_DASHES = 36 ByteSize = 16 StringLength = 32 StringLengthWithDashes = 36 )
document offsets and lengths
Variables ¶
var ( // ErrInvalidUUID means we failed to parse the given uuid. ErrInvalidUUID = errors.New("error parsing uuid") )
Functions ¶
Types ¶
type UUID ¶
type UUID [UUID_BYTES]byte
UUID is an alias for an array of 16 bytes.
func FromString ¶
FromString returns a UUID object from a given string and optionally an error.
func FromStringUnsafe ¶
FromStringUnsafe returns a UUID object from a given string, ignoring any errors. (This function just calls FromString() and throws away the error.)
func MustFromString ¶
MustFromString returns a UUID object from a given string. It panics if the string can't be parsed. (This function just calls FromString() and panics on error.)
func (*UUID) Array ¶
func (u *UUID) Array() *[UUID_BYTES]byte
Array returns a ref to underlying type [16]byte, for modification.
func (UUID) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface (since go 1.2).
func (UUID) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface (since go 1.2).
func (*UUID) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface (since go 1.2).
func (*UUID) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface (since go 1.2).