Documentation
¶
Overview ¶
Package quuid provides strict RFC 9562 UUIDs and larger identifiers for Go.
Use UUIDv7 for standards-compatible, time-ordered database identifiers. Use BinaryUUID when a SQL driver requires exactly 16 bytes. Use ID for 256-bit public identifiers, StrongID for a larger collision-security margin, and Token for bearer secrets whose plaintext must not be logged or stored.
ParseUUID and ParseUUIDBytes are intentionally strict. ParseUUIDLoose is available only for controlled migration boundaries.
Example ¶
package main
import (
"fmt"
"github.com/MeViksry/quuid"
)
func main() {
id := quuid.DeriveID("customers", []byte("customer-42"))
parsed := quuid.MustParseID(id.String())
fmt.Println(id.Equal(parsed))
}
Output: true
Index ¶
- Constants
- Variables
- func ValidateRFC9562UUID(s string) error
- func ValidateUUID(s string) error
- func VerifyToken(presented string, expected TokenDigest) bool
- type BinaryUUID
- func (id BinaryUUID) AppendBinary(dst []byte) ([]byte, error)
- func (id BinaryUUID) AppendText(dst []byte) ([]byte, error)
- func (id BinaryUUID) Bytes() []byte
- func (id BinaryUUID) Compare(other BinaryUUID) int
- func (id BinaryUUID) Equal(other BinaryUUID) bool
- func (id BinaryUUID) IsZero() bool
- func (id BinaryUUID) MarshalBinary() ([]byte, error)
- func (id BinaryUUID) MarshalJSON() ([]byte, error)
- func (id BinaryUUID) MarshalText() ([]byte, error)
- func (id *BinaryUUID) Scan(src any) error
- func (id BinaryUUID) String() string
- func (id BinaryUUID) UUID() UUID
- func (id *BinaryUUID) UnmarshalBinary(data []byte) error
- func (id *BinaryUUID) UnmarshalJSON(data []byte) error
- func (id *BinaryUUID) UnmarshalText(text []byte) error
- func (id BinaryUUID) Value() (driver.Value, error)
- func (id BinaryUUID) Variant() Variant
- func (id BinaryUUID) Version() Version
- type Generator
- func (g *Generator) NewID() (ID, error)
- func (g *Generator) NewMonotonicSortableID() (SortableID, error)
- func (g *Generator) NewSortableID() (SortableID, error)
- func (g *Generator) NewStrongID() (StrongID, error)
- func (g *Generator) NewUUIDv4() (UUID, error)
- func (g *Generator) NewUUIDv6() (UUID, error)
- func (g *Generator) NewUUIDv7() (UUID, error)
- func (g *Generator) NewUUIDv8() (UUID, error)
- type ID
- func (id ID) AppendBinary(dst []byte) ([]byte, error)
- func (id ID) AppendText(dst []byte) ([]byte, error)
- func (id ID) Bytes() []byte
- func (id ID) Compare(other ID) int
- func (id ID) Equal(other ID) bool
- func (id ID) Hex() string
- func (id ID) IsZero() bool
- func (id ID) MarshalBinary() ([]byte, error)
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) MarshalText() ([]byte, error)
- func (id *ID) Scan(src any) error
- func (id ID) String() string
- func (id *ID) UnmarshalBinary(data []byte) error
- func (id *ID) UnmarshalJSON(data []byte) error
- func (id *ID) UnmarshalText(text []byte) error
- func (id ID) Value() (driver.Value, error)
- type NullBinaryUUID
- type NullID
- type NullUUID
- type SortableID
- func (id SortableID) AppendBinary(dst []byte) ([]byte, error)
- func (id SortableID) AppendText(dst []byte) ([]byte, error)
- func (id SortableID) Bytes() []byte
- func (id SortableID) Compare(other SortableID) int
- func (id SortableID) Entropy() ID
- func (id SortableID) Equal(other SortableID) bool
- func (id SortableID) Hex() string
- func (id SortableID) IsZero() bool
- func (id SortableID) MarshalBinary() ([]byte, error)
- func (id SortableID) MarshalJSON() ([]byte, error)
- func (id SortableID) MarshalText() ([]byte, error)
- func (id *SortableID) Scan(src any) error
- func (id SortableID) String() string
- func (id SortableID) Timestamp() time.Time
- func (id *SortableID) UnmarshalBinary(data []byte) error
- func (id *SortableID) UnmarshalJSON(data []byte) error
- func (id *SortableID) UnmarshalText(text []byte) error
- func (id SortableID) Value() (driver.Value, error)
- type StrongID
- func DeriveStrongID(namespace string, data []byte) StrongID
- func DeriveStrongIDKeyed(secret []byte, namespace string, data []byte) (StrongID, error)
- func MustNewStrongID() StrongID
- func MustParseStrongID(s string) StrongID
- func NewStrongID() (StrongID, error)
- func NewStrongIDFromReader(r io.Reader) (StrongID, error)
- func ParseStrongID(s string) (StrongID, error)
- func (id StrongID) AppendBinary(dst []byte) ([]byte, error)
- func (id StrongID) AppendText(dst []byte) ([]byte, error)
- func (id StrongID) Bytes() []byte
- func (id StrongID) Compare(other StrongID) int
- func (id StrongID) Equal(other StrongID) bool
- func (id StrongID) Hex() string
- func (id StrongID) IsZero() bool
- func (id StrongID) MarshalBinary() ([]byte, error)
- func (id StrongID) MarshalJSON() ([]byte, error)
- func (id StrongID) MarshalText() ([]byte, error)
- func (id *StrongID) Scan(src any) error
- func (id StrongID) String() string
- func (id *StrongID) UnmarshalBinary(data []byte) error
- func (id *StrongID) UnmarshalJSON(data []byte) error
- func (id *StrongID) UnmarshalText(text []byte) error
- func (id StrongID) Value() (driver.Value, error)
- type Token
- type TokenDigest
- type UUID
- func DeriveUUIDv8(namespace string, data []byte) UUID
- func DeriveUUIDv8Keyed(secret []byte, namespace string, data []byte) (UUID, error)
- func MustNewUUIDv4() UUID
- func MustNewUUIDv6() UUID
- func MustNewUUIDv7() UUID
- func MustNewUUIDv8() UUID
- func MustParseUUID(s string) UUID
- func NewUUIDv4() (UUID, error)
- func NewUUIDv4FromReader(r io.Reader) (UUID, error)
- func NewUUIDv6() (UUID, error)
- func NewUUIDv6At(t time.Time, r io.Reader) (UUID, error)
- func NewUUIDv7() (UUID, error)
- func NewUUIDv7At(t time.Time, r io.Reader) (UUID, error)
- func NewUUIDv7FromReader(r io.Reader) (UUID, error)
- func NewUUIDv8() (UUID, error)
- func NewUUIDv8FromReader(r io.Reader) (UUID, error)
- func ParseUUID(s string) (UUID, error)
- func ParseUUIDBytes(text []byte) (UUID, error)
- func ParseUUIDLoose(s string) (UUID, error)
- func (id UUID) AppendBinary(dst []byte) ([]byte, error)
- func (id UUID) AppendText(dst []byte) ([]byte, error)
- func (id UUID) Binary() BinaryUUID
- func (id UUID) Bytes() []byte
- func (id UUID) Compare(other UUID) int
- func (id UUID) Equal(other UUID) bool
- func (id UUID) IsZero() bool
- func (id UUID) MarshalBinary() ([]byte, error)
- func (id UUID) MarshalJSON() ([]byte, error)
- func (id UUID) MarshalText() ([]byte, error)
- func (id *UUID) Scan(src any) error
- func (id UUID) String() string
- func (id UUID) Time() (time.Time, error)
- func (id *UUID) UnmarshalBinary(data []byte) error
- func (id *UUID) UnmarshalJSON(data []byte) error
- func (id *UUID) UnmarshalText(text []byte) error
- func (id UUID) Value() (driver.Value, error)
- func (id UUID) Variant() Variant
- func (id UUID) Version() Version
- type Variant
- type Version
Examples ¶
Constants ¶
const (
IDSize = 32
)
IDSize is the binary size of an ID in bytes.
const (
SortableIDSize = 40
)
SortableIDSize is the binary size of a SortableID in bytes.
const (
StrongIDSize = 48
)
StrongIDSize is the binary size of a StrongID in bytes.
const (
TokenSize = 32
)
TokenSize is the binary size of a Token in bytes.
const UUIDSize = 16
UUIDSize is the binary size of a UUID in bytes.
Variables ¶
var ( // ErrInvalidLength indicates that an identifier has an unexpected text or binary length. ErrInvalidLength = errors.New("quuid: invalid identifier length") // ErrInvalidEncoding indicates malformed or non-canonical identifier encoding. ErrInvalidEncoding = errors.New("quuid: invalid identifier encoding") // ErrInvalidPrefix indicates that a type-specific text prefix is incorrect. ErrInvalidPrefix = errors.New("quuid: invalid identifier prefix") // ErrNilValue indicates that SQL NULL or JSON null was assigned to a non-nullable type. ErrNilValue = errors.New("quuid: nil cannot be assigned to a non-null identifier") // ErrZeroEntropy indicates that a test or custom entropy source returned only zero bytes. ErrZeroEntropy = errors.New("quuid: entropy source returned an all-zero value") // ErrWeakSecret indicates that a keyed-derivation secret is shorter than 32 bytes. ErrWeakSecret = errors.New("quuid: secret must contain at least 32 bytes") // ErrTimeOutOfRange indicates that a timestamp cannot be represented by the requested identifier layout. ErrTimeOutOfRange = errors.New("quuid: time is outside the supported identifier range") // ErrCounterExhausted indicates that a monotonic random or timestamp field cannot be incremented further. ErrCounterExhausted = errors.New("quuid: monotonic identifier counter exhausted") // ErrInvalidSource indicates an unsupported database scanner source type. ErrInvalidSource = errors.New("quuid: unsupported database source type") )
Functions ¶
func ValidateRFC9562UUID ¶
ValidateRFC9562UUID validates canonical syntax, RFC variant bits, and a currently assigned version number from 1 through 8.
func ValidateUUID ¶
ValidateUUID validates the canonical UUID text representation.
func VerifyToken ¶
func VerifyToken(presented string, expected TokenDigest) bool
VerifyToken parses presented and compares its digest with expected in constant time.
Types ¶
type BinaryUUID ¶
type BinaryUUID UUID
BinaryUUID is an explicit database representation wrapper. It has the same logical UUID value but its driver.Value is []byte with exactly 16 bytes. There is no package-global SQL mode, so text and binary columns may coexist.
func (BinaryUUID) AppendBinary ¶
func (id BinaryUUID) AppendBinary(dst []byte) ([]byte, error)
AppendBinary appends the binary representation to dst.
func (BinaryUUID) AppendText ¶
func (id BinaryUUID) AppendText(dst []byte) ([]byte, error)
AppendText appends the canonical text representation to dst.
func (BinaryUUID) Bytes ¶
func (id BinaryUUID) Bytes() []byte
Bytes returns a defensive copy of the binary representation.
func (BinaryUUID) Compare ¶
func (id BinaryUUID) Compare(other BinaryUUID) int
Compare compares two values lexicographically and returns -1, 0, or 1.
func (BinaryUUID) Equal ¶
func (id BinaryUUID) Equal(other BinaryUUID) bool
Equal reports whether two values contain identical bytes.
func (BinaryUUID) IsZero ¶
func (id BinaryUUID) IsZero() bool
IsZero reports whether every byte is zero.
func (BinaryUUID) MarshalBinary ¶
func (id BinaryUUID) MarshalBinary() ([]byte, error)
MarshalBinary implements encoding.BinaryMarshaler.
func (BinaryUUID) MarshalJSON ¶
func (id BinaryUUID) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (BinaryUUID) MarshalText ¶
func (id BinaryUUID) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (*BinaryUUID) Scan ¶
func (id *BinaryUUID) Scan(src any) error
Scan implements database/sql.Scanner.
func (BinaryUUID) String ¶
func (id BinaryUUID) String() string
String returns the canonical text representation.
func (BinaryUUID) UUID ¶
func (id BinaryUUID) UUID() UUID
UUID returns the logical UUID represented by id.
func (*BinaryUUID) UnmarshalBinary ¶
func (id *BinaryUUID) UnmarshalBinary(data []byte) error
UnmarshalBinary implements encoding.BinaryUnmarshaler.
func (*BinaryUUID) UnmarshalJSON ¶
func (id *BinaryUUID) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (*BinaryUUID) UnmarshalText ¶
func (id *BinaryUUID) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
func (BinaryUUID) Value ¶
func (id BinaryUUID) Value() (driver.Value, error)
Value implements database/sql/driver.Valuer.
func (BinaryUUID) Variant ¶
func (id BinaryUUID) Variant() Variant
Variant returns the UUID variant field.
func (BinaryUUID) Version ¶
func (id BinaryUUID) Version() Version
Version returns the UUID version field.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator owns an entropy source, clock, and monotonic state. Its methods are safe for concurrent use. A Generator never uses global randomness settings.
func NewGenerator ¶
func NewGenerator() *Generator
NewGenerator returns a generator backed by crypto/rand.Reader and time.Now.
func NewGeneratorWith ¶
NewGeneratorWith returns a generator with explicit entropy and clock sources. It is intended for deterministic tests, approved DRBG/HSM integrations, and applications that need control over time-bearing identifiers.
func (*Generator) NewMonotonicSortableID ¶
func (g *Generator) NewMonotonicSortableID() (SortableID, error)
NewMonotonicSortableID returns a strictly increasing process-local SortableID.
func (*Generator) NewSortableID ¶
func (g *Generator) NewSortableID() (SortableID, error)
NewSortableID returns a new sortable identifier using the generator clock and entropy source.
func (*Generator) NewStrongID ¶
NewStrongID returns a new strong identifier using the generator entropy source.
func (*Generator) NewUUIDv6 ¶
NewUUIDv6 returns a strictly increasing process-local UUIDv6. Its random clock-sequence and node bits are sampled once per Generator. When the clock does not advance, the 60-bit timestamp is advanced by one 100ns tick.
type ID ¶
ID is a 256-bit cryptographically random identifier.
A quantum computer running an idealized Grover search would still require roughly 2^128 work to guess a specific uniformly random ID. ID is not an authentication mechanism; use Token for secrets and access credentials.
func DeriveID ¶
DeriveID deterministically derives an ID using SHA-512/256 and domain separation. The result is stable but not secret and may reveal equality of equal inputs.
func DeriveIDKeyed ¶
DeriveIDKeyed deterministically derives an unguessable ID using HMAC-SHA-512/256. secret must contain at least 32 random bytes.
func MustNewID ¶
func MustNewID() ID
MustNewID is like NewID but panics if the operating system entropy source fails.
func MustParseID ¶
MustParseID is like ParseID but panics on malformed input.
func NewIDFromReader ¶
NewIDFromReader returns a new ID using r as its entropy source. It is primarily useful for deterministic testing and specialized HSM/DRBG integrations.
func (ID) AppendBinary ¶
AppendBinary appends the binary representation to dst.
func (ID) AppendText ¶
AppendText appends the canonical text representation to dst.
func (ID) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler.
func (ID) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (ID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*ID) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*ID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type NullBinaryUUID ¶
NullBinaryUUID is the nullable counterpart of BinaryUUID. Valid values are written as exactly 16 bytes; invalid values are written as SQL NULL.
func NewNullBinaryUUID ¶
func NewNullBinaryUUID(id UUID) NullBinaryUUID
NewNullBinaryUUID marks id as a valid binary UUID value even when it is NilUUID.
func ToNullBinaryUUID ¶
func ToNullBinaryUUID(id UUID) NullBinaryUUID
ToNullBinaryUUID returns an invalid value for NilUUID and a valid value otherwise.
func (NullBinaryUUID) MarshalJSON ¶
func (n NullBinaryUUID) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*NullBinaryUUID) Scan ¶
func (n *NullBinaryUUID) Scan(src any) error
Scan implements database/sql.Scanner.
func (*NullBinaryUUID) UnmarshalJSON ¶
func (n *NullBinaryUUID) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type NullID ¶
NullID represents an ID that may be NULL in SQL or null in JSON.
func (NullID) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*NullID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type NullUUID ¶
NullUUID represents a UUID that may be SQL NULL or JSON null.
func NewNullUUID ¶
NewNullUUID marks id as valid even when it is NilUUID.
func ToNullUUID ¶
ToNullUUID returns an invalid value for NilUUID and a valid value otherwise.
func (NullUUID) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*NullUUID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type SortableID ¶
type SortableID [SortableIDSize]byte
SortableID contains an 8-byte Unix millisecond timestamp followed by 32 bytes of cryptographic entropy. Canonical text values sort by timestamp. The timestamp is intentionally visible; do not use this type when creation time must remain private.
func MustNewSortableID ¶
func MustNewSortableID() SortableID
MustNewSortableID is like NewSortableID but panics when generation fails.
func MustParseSortableID ¶
func MustParseSortableID(s string) SortableID
MustParseSortableID is like ParseSortableID but panics on malformed input.
func NewSortableID ¶
func NewSortableID() (SortableID, error)
NewSortableID returns a new sortable identifier using the generator clock and entropy source.
func NewSortableIDAt ¶
NewSortableIDAt returns a SortableID for t using r as its entropy source.
func ParseSortableID ¶
func ParseSortableID(s string) (SortableID, error)
ParseSortableID parses a SortableID from its supported text representations.
func (SortableID) AppendBinary ¶
func (id SortableID) AppendBinary(dst []byte) ([]byte, error)
AppendBinary appends the binary representation to dst.
func (SortableID) AppendText ¶
func (id SortableID) AppendText(dst []byte) ([]byte, error)
AppendText appends the canonical text representation to dst.
func (SortableID) Bytes ¶
func (id SortableID) Bytes() []byte
Bytes returns a defensive copy of the binary representation.
func (SortableID) Compare ¶
func (id SortableID) Compare(other SortableID) int
Compare compares two values lexicographically and returns -1, 0, or 1.
func (SortableID) Entropy ¶
func (id SortableID) Entropy() ID
Entropy returns the 256-bit random portion of a SortableID.
func (SortableID) Equal ¶
func (id SortableID) Equal(other SortableID) bool
Equal reports whether two values contain identical bytes.
func (SortableID) Hex ¶
func (id SortableID) Hex() string
Hex returns the lowercase hexadecimal representation without a type prefix.
func (SortableID) IsZero ¶
func (id SortableID) IsZero() bool
IsZero reports whether every byte is zero.
func (SortableID) MarshalBinary ¶
func (id SortableID) MarshalBinary() ([]byte, error)
MarshalBinary implements encoding.BinaryMarshaler.
func (SortableID) MarshalJSON ¶
func (id SortableID) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (SortableID) MarshalText ¶
func (id SortableID) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (*SortableID) Scan ¶
func (id *SortableID) Scan(src any) error
Scan implements database/sql.Scanner.
func (SortableID) String ¶
func (id SortableID) String() string
String returns the canonical text representation.
func (SortableID) Timestamp ¶
func (id SortableID) Timestamp() time.Time
Timestamp returns the UTC timestamp embedded in a SortableID.
func (*SortableID) UnmarshalBinary ¶
func (id *SortableID) UnmarshalBinary(data []byte) error
UnmarshalBinary implements encoding.BinaryUnmarshaler.
func (*SortableID) UnmarshalJSON ¶
func (id *SortableID) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (*SortableID) UnmarshalText ¶
func (id *SortableID) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
type StrongID ¶
type StrongID [StrongIDSize]byte
StrongID is a 384-bit identifier for systems that want a larger security margin. Under generic idealized quantum collision search, 384 output bits target roughly 128 bits of collision resistance. It is longer than a UUID and is not RFC 9562 compatible.
func DeriveStrongID ¶
DeriveStrongID deterministically derives a StrongID using SHA-384 and domain separation.
func DeriveStrongIDKeyed ¶
DeriveStrongIDKeyed deterministically derives a StrongID using HMAC-SHA-512.
func MustNewStrongID ¶
func MustNewStrongID() StrongID
MustNewStrongID is like NewStrongID but panics when secure randomness fails.
func MustParseStrongID ¶
MustParseStrongID is like ParseStrongID but panics on malformed input.
func NewStrongID ¶
NewStrongID returns a new strong identifier using the generator entropy source.
func NewStrongIDFromReader ¶
NewStrongIDFromReader returns a new StrongID using r as its entropy source.
func ParseStrongID ¶
ParseStrongID parses a StrongID from its supported text representations.
func (StrongID) AppendBinary ¶
AppendBinary appends the binary representation to dst.
func (StrongID) AppendText ¶
AppendText appends the canonical text representation to dst.
func (StrongID) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler.
func (StrongID) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (StrongID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*StrongID) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler.
func (*StrongID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*StrongID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Token ¶
Token is a 256-bit bearer secret. Store TokenDigest, not the plaintext Token.
func MustNewToken ¶
func MustNewToken() Token
MustNewToken is like NewToken but panics when secure randomness fails.
func NewTokenFromReader ¶
NewTokenFromReader returns a new bearer token using r as its entropy source.
func ParseToken ¶
ParseToken parses a bearer token from text.
func (Token) Digest ¶
func (token Token) Digest() TokenDigest
Digest returns the one-way digest that should be stored for later verification.
func (Token) Redacted ¶
Redacted returns a log-safe token representation that does not reveal the complete secret.
type TokenDigest ¶
type TokenDigest [32]byte
TokenDigest is a one-way SHA-512/256 digest suitable for database storage.
func (TokenDigest) String ¶
func (digest TokenDigest) String() string
String returns the canonical text representation.
type UUID ¶
UUID is a 128-bit universally unique identifier encoded according to RFC 9562.
UUID is intentionally implemented by quuid instead of being an alias to an upstream type. This lets quuid provide strict parsing, deterministic SQL behavior, allocation-aware append methods, clock injection, and explicit binary database wrappers without global process settings.
func DeriveUUIDv8 ¶
DeriveUUIDv8 creates a deterministic UUIDv8 using SHA-512/256 and framed domain separation. It does not use MD5 or SHA-1.
func DeriveUUIDv8Keyed ¶
DeriveUUIDv8Keyed creates a deterministic UUIDv8 using HMAC-SHA-512/256. secret must contain at least 32 bytes from a cryptographically secure source.
func MustNewUUIDv4 ¶
func MustNewUUIDv4() UUID
MustNewUUIDv4 is like NewUUIDv4 but panics when secure randomness fails.
func MustNewUUIDv6 ¶
func MustNewUUIDv6() UUID
MustNewUUIDv6 is like NewUUIDv6 but panics when generation fails.
func MustNewUUIDv7 ¶
func MustNewUUIDv7() UUID
MustNewUUIDv7 is like NewUUIDv7 but panics when generation fails.
func MustNewUUIDv8 ¶
func MustNewUUIDv8() UUID
MustNewUUIDv8 is like NewUUIDv8 but panics when generation fails.
func MustParseUUID ¶
MustParseUUID is like ParseUUID but panics on malformed input.
func NewUUIDv4FromReader ¶
NewUUIDv4FromReader returns a random UUIDv4 generated from r.
func NewUUIDv6 ¶
NewUUIDv6 returns a process-local monotonic RFC 9562 UUIDv6. The embedded timestamp remains strictly increasing when multiple values are generated in the same 100-nanosecond interval or the wall clock moves backwards. Random clock-sequence and node bits are sampled once for the process generator.
func NewUUIDv6At ¶
NewUUIDv6At returns an RFC 9562 UUIDv6 for t without shared monotonic state. The random portion is read from r.
func NewUUIDv7 ¶
NewUUIDv7 returns a process-local monotonic UUIDv7. Values remain ordered when multiple UUIDs are generated in the same millisecond or the wall clock moves backwards. The guarantee does not extend across processes or hosts.
func NewUUIDv7At ¶
NewUUIDv7At creates an RFC 9562 UUIDv7 for t using random bits from r.
func NewUUIDv7FromReader ¶
NewUUIDv7FromReader creates a UUIDv7 using time.Now and r without preserving monotonic state between calls. Use Generator for injected clocks and monotonicity.
func NewUUIDv8FromReader ¶
NewUUIDv8FromReader returns a random application-defined UUIDv8 using r.
func ParseUUID ¶
ParseUUID accepts only the canonical 36-character UUID representation. It rejects surrounding whitespace, URNs, braces, raw hexadecimal strings, and Microsoft mixed-endian binary encodings.
func ParseUUIDBytes ¶
ParseUUIDBytes accepts only the canonical 36-byte UUID representation. It is useful for SQL drivers and message transports that expose textual UUIDs as []byte.
func ParseUUIDLoose ¶
ParseUUIDLoose is an explicit migration helper. It accepts canonical UUIDs, 32 hexadecimal digits, urn:uuid: values, and brace-wrapped canonical UUIDs. Surrounding ASCII whitespace is trimmed. New application input should use ParseUUID instead.
func (UUID) AppendBinary ¶
AppendBinary appends the 16-byte network-order UUID representation to dst.
func (UUID) AppendText ¶
AppendText appends the canonical UUID representation to dst.
func (UUID) Binary ¶
func (id UUID) Binary() BinaryUUID
Binary returns an explicit binary database representation of id.
func (UUID) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler.
func (UUID) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (UUID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*UUID) Scan ¶
Scan accepts canonical UUID text or exactly 16 binary bytes. SQL NULL is rejected; use NullUUID or NullBinaryUUID for nullable columns.
func (*UUID) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler.
func (*UUID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*UUID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Variant ¶
type Variant byte
Variant identifies the UUID layout family.
const ( // VariantNCS identifies the historical NCS UUID variant. VariantNCS Variant = iota // VariantRFC9562 identifies the RFC 9562 variant, historically called RFC 4122. VariantRFC9562 // VariantMicrosoft identifies the historical Microsoft UUID variant. VariantMicrosoft // VariantFuture identifies the reserved future UUID variant. VariantFuture )
type Version ¶
type Version byte
Version is the four-bit UUID version field.
const ( // VersionUnknown represents an unassigned or unavailable UUID version. VersionUnknown Version = 0 // Version1 identifies UUIDv1. Version1 Version = 1 // Version2 identifies UUIDv2. Version2 Version = 2 // Version3 identifies name-based UUIDv3. Version3 Version = 3 // Version4 identifies random UUIDv4. Version4 Version = 4 // Version5 identifies name-based UUIDv5. Version5 Version = 5 // Version6 identifies reordered-time UUIDv6. Version6 Version = 6 // Version7 identifies Unix-time UUIDv7. Version7 Version = 7 // Version8 identifies application-defined UUIDv8. Version8 Version = 8 )