Documentation ¶
Index ¶
- Constants
- func DecodeNodeID(octets []byte) ([]byte, error)
- func DecodeVariant(octets []byte) byte
- func DecodeVariantOrFail(octets []byte) (byte, error)
- func DecodeVersion(octets []byte) byte
- func DecodeVersionOrFail(octets []byte) (byte, error)
- func EncodeVariant(octets []byte, variant byte) error
- func EncodeVersion(octets []byte, version byte) error
- func Equal(a UUID, b UUID) bool
- func EqualP(a *UUID, b *UUID) bool
- func HasNamespaceInitError() bool
- func IsMalformedFormat(err error) bool
- func IsMalformedOctets(err error) bool
- func MarshalBraced(octets []byte) ([]byte, error)
- func MarshalHyphened(octets []byte) ([]byte, error)
- func MarshalHyphenless(octets []byte) ([]byte, error)
- func MarshalShortened(octets []byte) ([]byte, error)
- func MarshalURN(octets []byte) ([]byte, error)
- func NamespaceInitError() error
- func UnmarshalInto(destination []byte, text []byte) error
- type MalformedFormatError
- type MalformedOctetsError
- type UUID
- func EncodeNamespaceMD5(namespace *UUID, data []byte) *UUID
- func EncodeNamespaceSHA1(namespace *UUID, data []byte) *UUID
- func EncodeNil() *UUID
- func EncodeRandom() (*UUID, error)
- func EncodeRandomUsingReader(source io.Reader) (*UUID, error)
- func EncodeTimebased() (*UUID, error)
- func New(octets []byte) (*UUID, error)
- func Unmarshal(text []byte) (*UUID, error)
- func (u *UUID) Braced() []byte
- func (u *UUID) GoString() string
- func (u *UUID) Hyphened() []byte
- func (u *UUID) Hyphenless() []byte
- func (u UUID) Octets() []byte
- func (u *UUID) Shortened() []byte
- func (u *UUID) String() string
- func (u *UUID) URN() []byte
- func (u *UUID) Variant() byte
- func (u *UUID) Version() byte
Constants ¶
const ( // UUID version is unknown VersionUnknown byte = iota // UUID is based on date-time and MAC address. Version1 // UUID is based on date-time and MAC address, // DCE security version. Although the RFC does // specify the DCE version, the implementation // for the DCE version is omitted by this package. Version2 // UUID is based on namespace-name (MD5 hashed). Version3 // UUID is based on random secure octets. Version4 // UUID is based on namespace-name (SHA1 hashed). Version5 )
UUID versions as defined in RFC 4122; Section 4.1.3 "Version". Only active and representative if UUID variant is `VariantRFC`.
const ( // UUID variant is NCS reserved. VariantNCS byte = iota // UUID variant is RFC compliant. VariantRFC // UUID variant is Microsoft reserved. VariantMicrosoft // UUID variant is reserved for future definitions. VariantFuture // UUID variant is unknown. VariantUnknown = 255 )
UUID layout variants as defined in RFC 4122; Section 4.1.2 "Variant".
Variables ¶
This section is empty.
Functions ¶
func DecodeNodeID ¶
DecodeNodeID decodes the node ID of a apparent UUID byte slice of version one. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets, or, when the version of the apparent UUID byte slice does not match const `Version1`.
func DecodeVariant ¶
DecodeVariant decodes the variant of a apparent UUID byte slice. Returns const `VariantFuture` if the variant could not be matched against known variants. Is guaranteed to return const `VariantUnknown` if the passed byte slice is subceeding or exceeding the required amount of octets.
func DecodeVariantOrFail ¶
DecodeVariantOrFail relinquishes the passed byte slice to `DecodeVariant`. Returns decoded variant and an error. 'OrFail' implies an error being returned if `DecodeVariant` returns const `VariantUnknown`.
func DecodeVersion ¶
DecodeVersion decodes the version of a apparent UUID byte slice. Is guaranteed to return const `VersionUnknown` if the passed byte slice is subceeding or exceeding the required amount of octets.
func DecodeVersionOrFail ¶
DecodeVersionOrFail relinquishes the passed byte slice to `DecodeVersion`. Returns decoded version and an error. 'OrFail' implies an error being returned if `DecodeVersion` returns const `VersionUnknown`.
func EncodeVariant ¶
EncodeVariant encodes the specified version into a apparent UUID byte slice. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.
func EncodeVersion ¶
EncodeVersion encodes the specified version into a apparent UUID byte slice. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.
func HasNamespaceInitError ¶
func HasNamespaceInitError() bool
HasNamespaceInitError reports whether an error occurred whilst initializing all namespace UUIDs. If you rely on namespace UUID encoding and `HasNamespaceInitError` returns `true`, please ensure to handle the error or exit gracefully.
func IsMalformedFormat ¶
IsMalformedFormat returns a boolean indicating whether the error is known to report that a apparent UUID string format is malformed. That is, if the faulty text does not match any of the format lengths or if the faulty text contains an invalid character.
func IsMalformedOctets ¶
IsMalformedOctets returns a boolean indicating whether the error is known to report that a apparent UUID byte slice is subceeding or exceeding the required amount of octets.
func MarshalBraced ¶
MarshalBraced marshals a apparent UUID byte slice into a hyphened UUID string representation encapsulated with opening and closing curly braces. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.
func MarshalHyphened ¶
MarshalHyphened marshals a apparent UUID byte slice into a hyphened UUID string representation. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.
func MarshalHyphenless ¶
MarshalHyphenless marshals a apparent UUID byte slice into a hyphenless UUID string representation. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.
func MarshalShortened ¶
MarshalShortened marshals a apparent UUID byte slice into a shortened UUID string representation. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.
func MarshalURN ¶
MarshalURN marshals a apparent UUID byte slice into a hyphened UUID string representation prefixed with `urn:uuid:`. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.
func NamespaceInitError ¶
func NamespaceInitError() error
NamespaceInitError yields the unexported `namespaceInitError` variable. See `HasNamespaceInitError` for further details.
func UnmarshalInto ¶
UnmarshalInto unmarshalls an apparent UUID string to the specified destination buffer. Supports all canonical known UUID formattings such as the hyphened, hyphenless braced and URN-prefixed. Is guaranteed to return an error if none of the named formats can be match. That is, if the input string does not match any of the given lengths: 32/hyphened, 36/hyphenless, 38/braced and 45/URN-prefixed.
Types ¶
type MalformedFormatError ¶
type MalformedFormatError struct {
Text []byte
}
MalformedFormatError occurs if a apparent UUID string subceeds or exceeds in its length. That is, if the string length does not match either 32, 36, 38, 45. Also occurs if the apparent UUID string contains invalid characters.
func (MalformedFormatError) Error ¶
func (e MalformedFormatError) Error() string
Error returns a string representation with a exhaustive message telling what the cause of this error is. If the faulty text does not match any of the format lengths, it prints current and required length. If the faulty text contains an invalid character, it prints the UUID string with the invalid character encapsulated.
type MalformedOctetsError ¶
type MalformedOctetsError struct {
Octets []byte
}
MalformedOctetsError occurs if a apparent UUID byte slice subceeds or exceeds the required amount of octets.
func (MalformedOctetsError) Error ¶
func (e MalformedOctetsError) Error() string
Error returns a string representation with a exhaustive message telling whether the apparent UUID byte slice subceeds or exceeds the amount of octets.
func (MalformedOctetsError) ExceedsLength ¶
func (e MalformedOctetsError) ExceedsLength() bool
ExceedsLength determines if the apparent UUID byte slice is subceeding or exceeding the required amount of octets.
func (MalformedOctetsError) RequiredOctets ¶
func (e MalformedOctetsError) RequiredOctets() int
RequiredOctets yields the required octet amount of a UUID byte slice.
func (MalformedOctetsError) SubceedsLength ¶
func (e MalformedOctetsError) SubceedsLength() bool
SubceedsLength determines if the apparent UUID byte slice is subceeding or exceeding the required amount of octets.
type UUID ¶
type UUID struct {
// contains filtered or unexported fields
}
An UUID is an universally unique identifier consisting of 16 octets representing either MAC & timestamp or namespace information. An UUID is usually formatted in a 36 character wide hexadecimal string representation, split apart in five groups using hyphens.
var ( NamespaceDNS *UUID NamespaceURL *UUID NamespaceOID *UUID NamespaceX500 *UUID NamespaceNil *UUID )
Predefined and commonly known namespace UUIDs.
func EncodeNamespaceMD5 ¶
EncodeNamespaceMD5 encodes a new UUID of version three, based on the given namespace and domain. Supplied data will be hashed using MD5.
func EncodeNamespaceSHA1 ¶
EncodeNamespaceSHA1 encodes a new UUID of version five, based on the given namespace and domain. Supplied data will be hashed using SHA1.
func EncodeNil ¶
func EncodeNil() *UUID
EncodeNil encodes a new UUID with all underlying octets zeroed out. See RFC 4122; Section 4.1.7 "Nil UUID".
func EncodeRandom ¶
EncodeRandom encodes a new UUID using random octets. Returned UUID is guaranteed to be always of version `Version4` and variant `VariantRFC`.
func EncodeRandomUsingReader ¶
EncodeRandomUsingReader encodes a new UUID using random octets. Reads octets from the given `io.Reader`. Is guaranteed to return an error if the given reader does not fully read 16 octets as the underlying implementation calls `io.ReadFull` on the supplied `io.Reader`.
func EncodeTimebased ¶
EncodeTimebased encodes a new UUID of version one, based on the current node ID (MAC address), clock sequence as well as the current time.
func New ¶
New creates a UUID struct from a apparent UUID byte slice. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.
func Unmarshal ¶
Unmarshal unmarshalls an apparent UUID string to a UUID struct. Supports all canonical known UUID formattings such as the hyphened, hyphenless braced and URN-prefixed. Is guaranteed to return an error if none of the named formats can be match. That is, if the input string does not match any of the given lengths: 32/hyphened, 36/hyphenless, 38/braced and 45/URN-prefixed.
func (*UUID) Braced ¶
Braced marshals this UUID's underlying octets into a hyphened UUID string representation encapsulated with opening and closing curly braces.
func (*UUID) Hyphened ¶
Hyphened marshals this UUID's underlying octets into a hyphened UUID string representation.
func (*UUID) Hyphenless ¶
Hyphenless marshals this UUID's underlying octets into a hyphenless UUID string representation.
func (*UUID) Shortened ¶
Shortened marshals this UUID's underlying octets into a shortened UUID string representation.
func (*UUID) URN ¶
URN marshals this UUID's underlying octets into a hyphened UUID string representation prefixed with `urn:uuid:`.