Documentation
¶
Overview ¶
Package uuid is a stdlib-only v4 UUID: type UUID [16]byte, New (v4 via crypto/rand), strict Parse/MustParse (8-4-4-4-12, errors.Is-able sentinel), String, IsZero, and MarshalText/UnmarshalText.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GenerateError ¶
type GenerateError struct{ Err error }
GenerateError reports a failure to read randomness while generating a UUID. It wraps the underlying reader error so callers can errors.As to a *GenerateError and errors.Unwrap (or read .Err) to inspect the cause.
func (*GenerateError) Error ¶
func (e *GenerateError) Error() string
func (*GenerateError) Unwrap ¶
func (e *GenerateError) Unwrap() error
type ParseError ¶
ParseError reports that a string was not a valid canonical UUID encoding. It carries the offending Input (always a UUID-sized string, so including it is bounded) and wraps the leaf sentinel errInvalidText as Err, which callers can reach via errors.As to a *ParseError or errors.Unwrap / errors.Is.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
func (*ParseError) Unwrap ¶
func (e *ParseError) Unwrap() error
type UUID ¶
type UUID [16]byte
UUID is a 128-bit identifier stored as a raw 16-byte array.
func MustParse ¶
MustParse is Parse for pinned, package-level constant IDs: it returns the decoded UUID or panics on a parse error. Use it only with compile-time literals you control, never with external input.
func New ¶
New returns a version-4 (random) UUID sourced from crypto/rand. It returns a *GenerateError if the randomness source cannot supply 16 bytes.
func Parse ¶
Parse decodes the canonical 8-4-4-4-12 hyphenated form into a UUID. Hyphens must sit at their fixed offsets and the remaining positions must be hex digits; hex is case-insensitive, and the decoded value is normalized so String/MarshalText always re-emit lowercase. Any structural or hex failure yields the zero UUID and a *ParseError wrapping errInvalidText (fail-secure: no partial value on error).
func (UUID) MarshalText ¶
MarshalText encodes u as its canonical 8-4-4-4-12 hyphenated form, so JSON (and any other encoding.TextMarshaler consumer) emits a readable string rather than a 16-int byte array.
func (*UUID) UnmarshalText ¶
UnmarshalText parses the 8-4-4-4-12 hyphenated form back into the 16 bytes by delegating to Parse (the single parsing implementation). The input must have hyphens at the fixed offsets and hex digits elsewhere; hex digits are case-insensitive (both 0x0a and 0x0A decode to 0x0a). The decoded value is normalized, so String/MarshalText always re-emit lowercase. Structurally invalid input returns a *ParseError (which unwraps to errInvalidText) and leaves the receiver unchanged (no partial write).