quuid

package module
v0.0.0-...-9361357 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 16 Imported by: 0

README

quuid

Strict RFC 9562 UUIDs, explicit SQL representations, monotonic UUIDv7, and larger security-oriented identifiers for Go.

CI Go Reference Go Version Release License Open Issues

Installation · Quick start · Database integration · Security · Migration

Overview

quuid is a standalone Go identifier library designed for applications that need stricter behavior and more explicit control than a minimal UUID package normally provides.

It includes:

  • RFC 9562 UUIDv4, UUIDv6, UUIDv7, and UUIDv8;
  • strict canonical UUID parsing by default;
  • a separately named compatibility parser for migrations;
  • process-local monotonic UUIDv7 generation;
  • injectable clocks and entropy readers;
  • explicit text and binary SQL representations without global flags;
  • nullable text and binary UUID types;
  • allocation-aware AppendText and AppendBinary methods;
  • 256-bit, 320-bit, and 384-bit identifiers for requirements that do not fit inside UUID's fixed 128-bit layout;
  • deterministic identifiers using SHA-512 family primitives and HMAC;
  • redacted bearer-token handling with constant-time digest verification;
  • no third-party runtime dependency;
  • no MD5 or SHA-1 import in the module dependency tree.

quuid is not a fork of github.com/google/uuid, and it does not require that module at runtime. Its UUID type has the same underlying [16]byte representation, so explicit conversion remains straightforward.

Security statement

A UUID is an identifier. It is not encryption, authentication, authorization, a signature, or an access-control decision.

RFC 9562 UUIDs are fixed at 128 bits. UUIDv4 and random UUIDv8 contain 122 unconstrained bits after version and variant fields are applied. No implementation can turn that fixed format into an unlimited-strength or universally quantum-resistant primitive.

For applications that need a larger generic search margin, quuid provides:

Type Binary size Intended use
UUID 16 bytes Standards-compatible identifiers
ID 32 bytes 256-bit opaque public identifiers
SortableID 40 bytes 64-bit timestamp plus 256-bit entropy
StrongID 48 bytes 384-bit identifiers with larger collision margin
Token 32 bytes 256-bit bearer credentials; store only the digest

An idealized Grover search reduces the generic preimage work factor of a uniformly random 256-bit value to roughly 128 bits. This is a conservative margin, not a guarantee against every future algorithm, compromised random source, side channel, implementation defect, or operational failure.

Design principles

  1. Strict by default. Canonical parsers reject whitespace, braces, URNs, raw hexadecimal UUIDs, malformed separators, and undocumented mixed-endian encodings.

  2. Compatibility is explicit. ParseUUIDLoose exists for migration boundaries. It is intentionally separate from ParseUUID.

  3. Database representation is local to the field. UUID writes text. BinaryUUID writes exactly 16 bytes. No package-global switch changes behavior for unrelated database connections.

  4. Time-bearing generation is testable. NewUUIDv6At, NewUUIDv7At, and Generator accept explicit time and entropy sources.

  5. Modern deterministic primitives only. Deterministic UUIDv8 and larger identifiers use SHA-512/256, SHA-384, or HMAC-SHA-512 family primitives. UUIDv3 and UUIDv5 are intentionally not implemented.

  6. Secrets are separate from identifiers. Token.String() is redacted. The full token is returned only by the explicit Secret() method.

Installation

go get github.com/MeViksry/quuid@latest

Requirements:

  • Go 1.23 or newer;
  • no external runtime dependency.

Quick start

package main

import (
    "fmt"
    "log"

    "github.com/MeViksry/quuid"
)

func main() {
    uuid7, err := quuid.NewUUIDv7()
    if err != nil {
        log.Fatal(err)
    }

    publicID, err := quuid.NewID()
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(uuid7)
    fmt.Println(publicID)
}

Choosing an identifier

Requirement Recommended API Ordering Security notes
Random standards-compatible UUID NewUUIDv4 Random 122 random bits
Time-ordered standards UUID NewUUIDv7 Process-local monotonic Timestamp is visible
RFC UUID compatible with legacy v1 ordering NewUUIDv6 Time ordered Random node; no MAC address
Application-defined deterministic UUID DeriveUUIDv8 Deterministic Equality of equal input is visible
Opaque public identifier NewID Random 256 random bits
Large time-sortable identifier NewSortableID Timestamp ordered Timestamp is visible
Larger collision-security margin NewStrongID Random 384 random bits
Bearer API credential NewToken Random Store TokenDigest, not plaintext

UUID API

UUIDv4
id, err := quuid.NewUUIDv4()

For deterministic testing or an approved custom DRBG/HSM reader:

id, err := quuid.NewUUIDv4FromReader(reader)
UUIDv6

UUIDv6 reorders the Gregorian timestamp fields used by UUIDv1 into a lexicographically sortable layout. quuid uses random clock-sequence and node bits, sampled once per generator, and never reads a network-interface MAC address. The package-level constructor is process-local monotonic and advances the embedded timestamp by one 100-nanosecond tick when the clock does not advance.

id, err := quuid.NewUUIDv6()

Generate for an explicit time:

id, err := quuid.NewUUIDv6At(timestamp, reader)

The implementation includes a conformance regression test using the RFC UUIDv6 example:

1ec9414c-232a-6b00-b3c8-9e6bdeced846
UUIDv7

The package-level constructor uses a concurrency-safe process-local monotonic generator:

id, err := quuid.NewUUIDv7()

When multiple values are generated in the same millisecond, the 74-bit random field is incremented. If the wall clock moves backwards, generation remains on the last emitted millisecond and continues incrementing. This improves index locality and guarantees ordering inside one process.

It does not provide global ordering across processes, containers, hosts, or regions.

For explicit time without shared monotonic state:

id, err := quuid.NewUUIDv7At(timestamp, reader)

For an injected clock with monotonic state:

generator, err := quuid.NewGeneratorWith(reader, clock)
if err != nil {
    return err
}

id, err := generator.NewUUIDv7()

Read the timestamp:

timestamp, err := id.Time()
UUIDv8

Random UUIDv8:

id, err := quuid.NewUUIDv8()

Deterministic UUIDv8 using SHA-512/256 and domain separation:

id := quuid.DeriveUUIDv8("invoice", []byte("INV-2026-00042"))

Keyed deterministic UUIDv8:

id, err := quuid.DeriveUUIDv8Keyed(
    secret,
    "customer",
    []byte("customer@example.com"),
)

The keyed secret must contain at least 32 bytes from a secure random source and should be stored in a KMS, HSM, or managed secret store.

Strict and compatibility parsing

Strict parser
id, err := quuid.ParseUUID("018fbd2e-7b46-7cc0-98c4-89e6f6dc0c22")

ParseUUID accepts exactly the canonical 36-character representation. ParseUUIDBytes applies the same strict rules to canonical []byte input from SQL drivers, queues, and wire protocols without converting through string first. Both reject:

" 018fbd2e-7b46-7cc0-98c4-89e6f6dc0c22"
"018fbd2e-7b46-7cc0-98c4-89e6f6dc0c22 "
{018fbd2e-7b46-7cc0-98c4-89e6f6dc0c22}
urn:uuid:018fbd2e-7b46-7cc0-98c4-89e6f6dc0c22
018fbd2e7b467cc098c489e6f6dc0c22

Uppercase hexadecimal digits are accepted and canonical output is always lowercase.

Compatibility parser

Use the loose parser only at a controlled migration boundary:

id, err := quuid.ParseUUIDLoose(input)

It accepts:

  • canonical UUID text;
  • surrounding whitespace;
  • urn:uuid: values;
  • brace-wrapped canonical values;
  • exactly 32 hexadecimal digits.

It does not implement Microsoft mixed-endian reinterpretation.

UUID inspection

id := quuid.MustParseUUID("018fbd2e-7b46-7cc0-98c4-89e6f6dc0c22")

fmt.Println(id.Version())
fmt.Println(id.Variant())
fmt.Println(id.IsZero())
fmt.Println(id.Equal(other))
fmt.Println(id.Compare(other))

Validation options:

err := quuid.ValidateUUID(text)
err = quuid.ValidateRFC9562UUID(text)

ValidateUUID checks canonical syntax. ValidateRFC9562UUID additionally requires the RFC variant and an assigned version from 1 through 8.

Database integration

Portable text representation

UUID implements database/sql.Scanner and driver.Valuer.

type Account struct {
    ID quuid.UUID
}

UUID.Value() returns the canonical string. This is suitable for:

  • PostgreSQL uuid;
  • MySQL CHAR(36);
  • SQLite TEXT;
  • text-compatible database drivers.

Scanning accepts canonical UUID text or exactly 16 binary bytes.

Binary representation

Use BinaryUUID when the database column expects exactly 16 bytes:

type Account struct {
    ID quuid.BinaryUUID
}

Convert between logical and binary representations:

id := quuid.MustNewUUIDv7()

binary := id.Binary()
logical := binary.UUID()

BinaryUUID.Value() returns a defensive []byte copy with length 16. It is suitable for:

  • MySQL or MariaDB BINARY(16);
  • SQLite BLOB;
  • PostgreSQL bytea;
  • drivers that explicitly require []byte.

The bytes use standard RFC network order. quuid does not silently apply MySQL's optional UUID_TO_BIN(..., 1) field-swapping convention.

Text and binary columns in the same application

No global mode is required:

type Record struct {
    PostgreSQLID quuid.UUID
    MySQLID      quuid.BinaryUUID
}

Each field controls its own driver.Value. Multiple drivers and ORMs can coexist without process-wide behavior changes.

Nullable UUID
type Record struct {
    ParentID quuid.NullUUID
}

NullUUID.Scan treats these values as invalid/null:

  • SQL NULL;
  • empty string;
  • empty byte slice.

A malformed non-empty value returns an error and leaves Valid false.

nullable := quuid.ToNullUUID(id)

ToNullUUID(quuid.NilUUID) returns an invalid value. NewNullUUID(id) marks the value valid even when id is NilUUID.

Nullable binary UUID
type Record struct {
    ParentID quuid.NullBinaryUUID
}

Valid values are written as exactly 16 bytes. Invalid values are written as SQL NULL.

JSON, text, and binary encoding

UUID, ID, StrongID, and SortableID implement the standard marshal/unmarshal interfaces for JSON, text, and binary data.

encoded, err := json.Marshal(id)

UUID JSON uses canonical text:

"018fbd2e-7b46-7cc0-98c4-89e6f6dc0c22"

Non-nullable types reject JSON null. Use their nullable counterpart when null is a valid application state.

Allocation-aware append methods

The identifier types expose:

AppendText(dst []byte) ([]byte, error)
AppendBinary(dst []byte) ([]byte, error)

Example:

buffer := make([]byte, 0, 64)
buffer, err := id.AppendText(buffer)

These methods allow encoders to append into reusable buffers instead of allocating a new slice for each value.

Larger identifiers

ID

ID is a 256-bit opaque identifier with canonical Crockford Base32 text prefixed by qid_.

id, err := quuid.NewID()
parsed, err := quuid.ParseID(id.String())

Deterministic public ID:

id := quuid.DeriveID("customer", []byte("customer-42"))

Keyed deterministic ID:

id, err := quuid.DeriveIDKeyed(secret, "customer", input)
SortableID

SortableID contains:

8-byte unsigned Unix millisecond timestamp || 32-byte random entropy
id, err := quuid.NewSortableID()
fmt.Println(id.Timestamp())

Use a generator for strict process-local monotonic order:

g := quuid.NewGenerator()
id, err := g.NewMonotonicSortableID()
StrongID

StrongID is a 384-bit identifier prefixed by qsid_.

id, err := quuid.NewStrongID()

It is intended for systems that justify a larger quantum collision-search margin and can accept the additional storage and index cost.

Bearer tokens

Generate a token once and return its full value only to the caller:

token, err := quuid.NewToken()
if err != nil {
    return err
}

plaintext := token.Secret()
digest := token.Digest()

Store digest, not plaintext.

Verify a presented token:

valid := quuid.VerifyToken(presented, digest)

Token.String() and normal formatting are redacted to reduce accidental log disclosure:

qtk_…a1b2c3

Do not use UUID, ID, SortableID, or StrongID possession as authorization.

Migration from google/uuid

The underlying representation of both UUID types is [16]byte, so explicit conversion is direct:

import (
    googleuuid "github.com/google/uuid"
    "github.com/MeViksry/quuid"
)

googleID := googleuuid.New()
quuidID := quuid.UUID(googleID)
back := googleuuid.UUID(quuidID)

Important behavior changes:

Area Migration impact
Parsing ParseUUID is canonical and strict; use ParseUUIDLoose only for controlled legacy input
SQL UUID writes text; use BinaryUUID for BINARY(16) or BLOB columns
Null values Empty string and empty bytes produce invalid NullUUID rather than a valid zero value
UUIDv7 Package constructor is process-local monotonic
UUIDv6 Process-local monotonic timestamp, random node bits, and no MAC address collection
Deterministic UUID Use UUIDv8 with SHA-512/256 or HMAC; no UUIDv3/UUIDv5 helpers
Randomness No global random pool toggle

Hardening against known UUID-library failure modes

The following table documents how quuid handles the classes of problems raised in public UUID-library issue trackers.

Concern Related upstream issue quuid behavior
SQL binary representation google/uuid#46 Explicit BinaryUUID and NullBinaryUUID; no global flag
Legacy MD5/SHA-1 hashes google/uuid#218 No UUIDv3/v5 API, no MD5/SHA-1 imports, SHA-512-family UUIDv8 derivation
Future Go standard UUID package google/uuid#221 No dependency lock-in; UUID backend is isolated and can adopt a verified standard implementation without changing public types
Allocation-aware encoding google/uuid#193 AppendText and AppendBinary implemented
PostgreSQL-style UUIDv7 locality google/uuid#191 Process-local monotonic UUIDv7 with rollback handling
Injectable time source google/uuid#165 NewUUIDv6At, NewUUIDv7At, and NewGeneratorWith
Incorrect UUIDv6 field layout google/uuid#159 RFC layout plus published UUIDv6 example regression test
UUIDv6 decoded time moves backward google/uuid#199 Process-local monotonic UUIDv6 timestamp with 100-nanosecond stepping
Leading/trailing spaces accepted google/uuid#147 Strict parser rejects whitespace; compatibility parser is separately named
Nil UUID documentation ambiguity google/uuid#112 NilUUID is explicitly documented as the all-zero UUID and not SQL NULL
Missing zero/null helpers google/uuid#113 IsZero, ToNullUUID, ToNullBinaryUUID
Empty string marked valid in nullable scan google/uuid#109 Empty string and empty bytes set Valid=false
Missing UUIDv8 reference API google/uuid#103 Random, deterministic, and keyed UUIDv8 APIs with version/variant tests
Missing equality helper google/uuid#100 Equal and Compare methods
Process-global random pool behavior google/uuid#86 No mutable global random-pool switch; generators own their reader
Unexpected panic from convenience constructor google/uuid#97 Default constructors return errors; panic behavior is limited to explicitly named Must... APIs
Overly permissive or mixed-endian parsing google/uuid#60 Canonical strict parser and explicitly bounded loose parser
Ambiguous output casing google/uuid#94 Canonical lowercase output; uppercase hexadecimal input remains valid
Variant documentation ambiguity google/uuid#91 Public Variant type and explicit RFC validation

A mitigation table is not a substitute for review. Every behavior above is covered by tests or a CI policy check.

Concurrency and ordering guarantees

  • Package-level random constructors are safe for concurrent use.
  • Generator methods are protected by a mutex.
  • NewUUIDv6 and Generator.NewUUIDv6 are strictly increasing inside one generator instance.
  • NewUUIDv7 and Generator.NewUUIDv7 are strictly increasing inside one generator instance.
  • NewMonotonicSortableID is strictly increasing inside one generator instance.
  • No distributed total-order claim is made.
  • Database uniqueness constraints remain mandatory.

Error handling

Random constructors return errors:

id, err := quuid.NewID()

Must... helpers panic and should be limited to initialization paths where entropy failure is unrecoverable:

id := quuid.MustNewUUIDv7()

Parsers return stable sentinel errors where appropriate:

errors.Is(err, quuid.ErrInvalidLength)
errors.Is(err, quuid.ErrInvalidEncoding)
errors.Is(err, quuid.ErrInvalidPrefix)
errors.Is(err, quuid.ErrNilValue)
errors.Is(err, quuid.ErrWeakSecret)
errors.Is(err, quuid.ErrTimeOutOfRange)

Command-line tool

Build the CLI:

go install github.com/MeViksry/quuid/cmd/quuid@latest

Generate values:

quuid -type uuid7
quuid -type uuid6 -n 10
quuid -type id -n 5
quuid -type strong
quuid -type sortable
quuid -type token
quuid -type uuid8 -namespace invoice -data INV-2026-00042
quuid -type uuid7 -json
quuid -version

Automated releases and packages

GitHub automation publishes release assets and packages without adding runtime dependencies to the module. The workflows run on the repository's self-hosted runner label, matching the CI setup.

Every push to main updates a single prerelease named nightly with fresh CLI archives and checksums. This keeps the Releases page active without creating a noisy release for every commit.

Push a semantic version tag to create an official GitHub Release:

git tag v0.1.0
git push origin v0.1.0

The release workflow verifies the candidate, builds quuid CLI archives for Linux, macOS, and Windows on amd64 and arm64, generates checksums.txt, and uploads everything to the GitHub Release.

The package workflow publishes a GitHub Container Registry image for the CLI:

  • ghcr.io/meviksry/quuid:edge on pushes to main;
  • ghcr.io/meviksry/quuid:sha-<commit> on every packaged push;
  • ghcr.io/meviksry/quuid:vX.Y.Z on release tags;
  • ghcr.io/meviksry/quuid:latest on stable release tags.

The package runner must have Docker available and permission to push packages with GITHUB_TOKEN.

Testing

Run the complete local verification suite:

make check

Individual commands:

go test ./...
go test -race ./...
go vet ./...
go test -run '^$' -bench . -benchmem ./...

The unit suite includes a fixed-clock concurrent UUIDv7 stress test. The benchmark suite includes sequential and parallel UUIDv7 generation plus parser allocation checks.

Parser fuzzing:

go test -fuzz='^FuzzParseUUID$' -fuzztime=30s .
go test -fuzz='^FuzzParseUUIDBytes$' -fuzztime=30s .
go test -fuzz='^FuzzParseUUIDLoose$' -fuzztime=30s .
go test -fuzz='^FuzzParseID$' -fuzztime=30s .
go test -fuzz='^FuzzParseStrongID$' -fuzztime=30s .
go test -fuzz='^FuzzParseSortableID$' -fuzztime=30s .

CI verifies multiple supported Go versions and operating systems, runs the race detector, go vet, vulnerability scanning, and a dependency-tree check that rejects crypto/md5 and crypto/sha1.

Compatibility policy

Before v1.0, small API refinements may occur in minor releases and are documented in CHANGELOG.md.

After v1.0:

  • exported API compatibility follows semantic versioning;
  • parsing behavior remains strict by default;
  • security-sensitive behavior changes require regression tests and release notes;
  • deprecated behavior is not silently re-enabled through global switches.

Project documentation

  • DESIGN.md describes layouts, generation, parsing, and database representation.
  • SECURITY.md defines the vulnerability-reporting process and cryptographic scope.
  • CONTRIBUTING.md describes development and pull-request requirements.
  • CHANGELOG.md records release changes.

Contributing

Focused contributions are welcome. New functionality should include:

  • tests for success and failure paths;
  • parser fuzz seeds when input handling changes;
  • documentation for security assumptions;
  • no custom cryptographic primitive;
  • no hidden global configuration that changes unrelated callers.

See CONTRIBUTING.md.

License

quuid is available under the MIT License. See LICENSE.

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

Examples

Constants

View Source
const (
	IDSize = 32
)

IDSize is the binary size of an ID in bytes.

View Source
const (
	SortableIDSize = 40
)

SortableIDSize is the binary size of a SortableID in bytes.

View Source
const (
	StrongIDSize = 48
)

StrongIDSize is the binary size of a StrongID in bytes.

View Source
const (
	TokenSize = 32
)

TokenSize is the binary size of a Token in bytes.

View Source
const UUIDSize = 16

UUIDSize is the binary size of a UUID in bytes.

Variables

View Source
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

func ValidateRFC9562UUID(s string) error

ValidateRFC9562UUID validates canonical syntax, RFC variant bits, and a currently assigned version number from 1 through 8.

func ValidateUUID

func ValidateUUID(s string) error

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

func NewGeneratorWith(reader io.Reader, clock func() time.Time) (*Generator, error)

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) NewID

func (g *Generator) NewID() (ID, error)

NewID returns a new identifier using the generator entropy source.

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

func (g *Generator) NewStrongID() (StrongID, error)

NewStrongID returns a new strong identifier using the generator entropy source.

func (*Generator) NewUUIDv4

func (g *Generator) NewUUIDv4() (UUID, error)

NewUUIDv4 returns a UUIDv4 using the generator's entropy source.

func (*Generator) NewUUIDv6

func (g *Generator) NewUUIDv6() (UUID, error)

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.

func (*Generator) NewUUIDv7

func (g *Generator) NewUUIDv7() (UUID, error)

NewUUIDv7 returns a strictly increasing process-local UUIDv7. On clock rollback, it holds the previous millisecond and increments the 74-bit random field. This mirrors the monotonic behavior expected for database locality.

func (*Generator) NewUUIDv8

func (g *Generator) NewUUIDv8() (UUID, error)

NewUUIDv8 returns a random UUIDv8 using the generator's entropy source.

type ID

type ID [IDSize]byte

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

func DeriveID(namespace string, data []byte) ID

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

func DeriveIDKeyed(secret []byte, namespace string, data []byte) (ID, error)

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

func MustParseID(s string) ID

MustParseID is like ParseID but panics on malformed input.

func NewID

func NewID() (ID, error)

NewID returns a new ID generated by crypto/rand.

func NewIDFromReader

func NewIDFromReader(r io.Reader) (ID, error)

NewIDFromReader returns a new ID using r as its entropy source. It is primarily useful for deterministic testing and specialized HSM/DRBG integrations.

func ParseID

func ParseID(s string) (ID, error)

ParseID parses an ID from its supported text representations.

func (ID) AppendBinary

func (id ID) AppendBinary(dst []byte) ([]byte, error)

AppendBinary appends the binary representation to dst.

func (ID) AppendText

func (id ID) AppendText(dst []byte) ([]byte, error)

AppendText appends the canonical text representation to dst.

func (ID) Bytes

func (id ID) Bytes() []byte

Bytes returns a defensive copy of the binary representation.

func (ID) Compare

func (id ID) Compare(other ID) int

Compare compares two values lexicographically and returns -1, 0, or 1.

func (ID) Equal

func (id ID) Equal(other ID) bool

Equal reports whether two values contain identical bytes.

func (ID) Hex

func (id ID) Hex() string

Hex returns the lowercase hexadecimal representation without a type prefix.

func (ID) IsZero

func (id ID) IsZero() bool

IsZero reports whether every byte is zero.

func (ID) MarshalBinary

func (id ID) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (ID) MarshalText

func (id ID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*ID) Scan

func (id *ID) Scan(src any) error

Scan implements database/sql.Scanner.

func (ID) String

func (id ID) String() string

String returns the canonical text representation.

func (*ID) UnmarshalBinary

func (id *ID) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (ID) Value

func (id ID) Value() (driver.Value, error)

Value implements database/sql/driver.Valuer.

type NullBinaryUUID

type NullBinaryUUID struct {
	UUID  UUID
	Valid bool
}

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.

func (NullBinaryUUID) Value

func (n NullBinaryUUID) Value() (driver.Value, error)

Value implements database/sql/driver.Valuer.

type NullID

type NullID struct {
	ID    ID
	Valid bool
}

NullID represents an ID that may be NULL in SQL or null in JSON.

func (NullID) MarshalJSON

func (n NullID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*NullID) Scan

func (n *NullID) Scan(src any) error

Scan implements database/sql.Scanner.

func (*NullID) UnmarshalJSON

func (n *NullID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (NullID) Value

func (n NullID) Value() (driver.Value, error)

Value implements database/sql/driver.Valuer.

type NullUUID

type NullUUID struct {
	UUID  UUID
	Valid bool
}

NullUUID represents a UUID that may be SQL NULL or JSON null.

func NewNullUUID

func NewNullUUID(id UUID) NullUUID

NewNullUUID marks id as valid even when it is NilUUID.

func ToNullUUID

func ToNullUUID(id UUID) NullUUID

ToNullUUID returns an invalid value for NilUUID and a valid value otherwise.

func (NullUUID) MarshalJSON

func (n NullUUID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*NullUUID) Scan

func (n *NullUUID) Scan(src any) error

Scan implements database/sql.Scanner.

func (*NullUUID) UnmarshalJSON

func (n *NullUUID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (NullUUID) Value

func (n NullUUID) Value() (driver.Value, error)

Value implements database/sql/driver.Valuer.

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

func NewSortableIDAt(t time.Time, r io.Reader) (SortableID, error)

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.

func (SortableID) Value

func (id SortableID) Value() (driver.Value, error)

Value implements database/sql/driver.Valuer.

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

func DeriveStrongID(namespace string, data []byte) StrongID

DeriveStrongID deterministically derives a StrongID using SHA-384 and domain separation.

func DeriveStrongIDKeyed

func DeriveStrongIDKeyed(secret []byte, namespace string, data []byte) (StrongID, error)

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

func MustParseStrongID(s string) StrongID

MustParseStrongID is like ParseStrongID but panics on malformed input.

func NewStrongID

func NewStrongID() (StrongID, error)

NewStrongID returns a new strong identifier using the generator entropy source.

func NewStrongIDFromReader

func NewStrongIDFromReader(r io.Reader) (StrongID, error)

NewStrongIDFromReader returns a new StrongID using r as its entropy source.

func ParseStrongID

func ParseStrongID(s string) (StrongID, error)

ParseStrongID parses a StrongID from its supported text representations.

func (StrongID) AppendBinary

func (id StrongID) AppendBinary(dst []byte) ([]byte, error)

AppendBinary appends the binary representation to dst.

func (StrongID) AppendText

func (id StrongID) AppendText(dst []byte) ([]byte, error)

AppendText appends the canonical text representation to dst.

func (StrongID) Bytes

func (id StrongID) Bytes() []byte

Bytes returns a defensive copy of the binary representation.

func (StrongID) Compare

func (id StrongID) Compare(other StrongID) int

Compare compares two values lexicographically and returns -1, 0, or 1.

func (StrongID) Equal

func (id StrongID) Equal(other StrongID) bool

Equal reports whether two values contain identical bytes.

func (StrongID) Hex

func (id StrongID) Hex() string

Hex returns the lowercase hexadecimal representation without a type prefix.

func (StrongID) IsZero

func (id StrongID) IsZero() bool

IsZero reports whether every byte is zero.

func (StrongID) MarshalBinary

func (id StrongID) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (StrongID) MarshalJSON

func (id StrongID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (StrongID) MarshalText

func (id StrongID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*StrongID) Scan

func (id *StrongID) Scan(src any) error

Scan implements database/sql.Scanner.

func (StrongID) String

func (id StrongID) String() string

String returns the canonical text representation.

func (*StrongID) UnmarshalBinary

func (id *StrongID) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*StrongID) UnmarshalJSON

func (id *StrongID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*StrongID) UnmarshalText

func (id *StrongID) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (StrongID) Value

func (id StrongID) Value() (driver.Value, error)

Value implements database/sql/driver.Valuer.

type Token

type Token [TokenSize]byte

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 NewToken

func NewToken() (Token, error)

NewToken returns a new bearer token generated from crypto/rand.

func NewTokenFromReader

func NewTokenFromReader(r io.Reader) (Token, error)

NewTokenFromReader returns a new bearer token using r as its entropy source.

func ParseToken

func ParseToken(s string) (Token, error)

ParseToken parses a bearer token from text.

func (Token) Bytes

func (token Token) Bytes() []byte

Bytes returns a defensive copy of the binary representation.

func (Token) Digest

func (token Token) Digest() TokenDigest

Digest returns the one-way digest that should be stored for later verification.

func (Token) Redacted

func (token Token) Redacted() string

Redacted returns a log-safe token representation that does not reveal the complete secret.

func (Token) Secret

func (token Token) Secret() string

Secret returns the complete bearer-token plaintext and should be used only at issuance or verification boundaries.

func (Token) String

func (token Token) String() string

String implements fmt.Stringer with a redacted representation so ordinary logging does not expose the bearer secret. Use Secret only at issuance time.

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

type UUID [UUIDSize]byte

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.

var (
	// NilUUID is the all-zero UUID. It is not SQL NULL.
	NilUUID UUID
	// MaxUUID is the all-one UUID defined by RFC 9562.
	MaxUUID = UUID{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
)

func DeriveUUIDv8

func DeriveUUIDv8(namespace string, data []byte) UUID

DeriveUUIDv8 creates a deterministic UUIDv8 using SHA-512/256 and framed domain separation. It does not use MD5 or SHA-1.

func DeriveUUIDv8Keyed

func DeriveUUIDv8Keyed(secret []byte, namespace string, data []byte) (UUID, error)

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

func MustParseUUID(s string) UUID

MustParseUUID is like ParseUUID but panics on malformed input.

func NewUUIDv4

func NewUUIDv4() (UUID, error)

NewUUIDv4 returns a random UUIDv4 generated from crypto/rand.

func NewUUIDv4FromReader

func NewUUIDv4FromReader(r io.Reader) (UUID, error)

NewUUIDv4FromReader returns a random UUIDv4 generated from r.

func NewUUIDv6

func NewUUIDv6() (UUID, error)

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

func NewUUIDv6At(t time.Time, r io.Reader) (UUID, error)

NewUUIDv6At returns an RFC 9562 UUIDv6 for t without shared monotonic state. The random portion is read from r.

func NewUUIDv7

func NewUUIDv7() (UUID, error)

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

func NewUUIDv7At(t time.Time, r io.Reader) (UUID, error)

NewUUIDv7At creates an RFC 9562 UUIDv7 for t using random bits from r.

func NewUUIDv7FromReader

func NewUUIDv7FromReader(r io.Reader) (UUID, error)

NewUUIDv7FromReader creates a UUIDv7 using time.Now and r without preserving monotonic state between calls. Use Generator for injected clocks and monotonicity.

func NewUUIDv8

func NewUUIDv8() (UUID, error)

NewUUIDv8 returns a random RFC 9562 UUIDv8.

func NewUUIDv8FromReader

func NewUUIDv8FromReader(r io.Reader) (UUID, error)

NewUUIDv8FromReader returns a random application-defined UUIDv8 using r.

func ParseUUID

func ParseUUID(s string) (UUID, error)

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

func ParseUUIDBytes(text []byte) (UUID, error)

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

func ParseUUIDLoose(s string) (UUID, error)

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

func (id UUID) AppendBinary(dst []byte) ([]byte, error)

AppendBinary appends the 16-byte network-order UUID representation to dst.

func (UUID) AppendText

func (id UUID) AppendText(dst []byte) ([]byte, error)

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) Bytes

func (id UUID) Bytes() []byte

Bytes returns a defensive copy of the binary representation.

func (UUID) Compare

func (id UUID) Compare(other UUID) int

Compare compares two values lexicographically and returns -1, 0, or 1.

func (UUID) Equal

func (id UUID) Equal(other UUID) bool

Equal reports whether two values contain identical bytes.

func (UUID) IsZero

func (id UUID) IsZero() bool

IsZero reports whether every byte is zero.

func (UUID) MarshalBinary

func (id UUID) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (UUID) MarshalJSON

func (id UUID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (UUID) MarshalText

func (id UUID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*UUID) Scan

func (id *UUID) Scan(src any) error

Scan accepts canonical UUID text or exactly 16 binary bytes. SQL NULL is rejected; use NullUUID or NullBinaryUUID for nullable columns.

func (UUID) String

func (id UUID) String() string

String returns the canonical text representation.

func (UUID) Time

func (id UUID) Time() (time.Time, error)

Time returns the embedded timestamp for UUIDv6 and UUIDv7.

func (*UUID) UnmarshalBinary

func (id *UUID) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*UUID) UnmarshalJSON

func (id *UUID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*UUID) UnmarshalText

func (id *UUID) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (UUID) Value

func (id UUID) Value() (driver.Value, error)

Value returns canonical UUID text. This is the safest portable default for PostgreSQL uuid columns and text-oriented drivers. Use UUID.Binary() for MySQL BINARY(16), SQLite BLOB, PostgreSQL bytea, or another binary column.

func (UUID) Variant

func (id UUID) Variant() Variant

Variant returns the UUID variant field.

func (UUID) Version

func (id UUID) Version() Version

Version returns the UUID version field.

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
)

func (Variant) String

func (v Variant) String() string

String returns the conventional UUID variant name.

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
)

func (Version) String

func (v Version) String() string

String returns the conventional UUID version name.

Directories

Path Synopsis
cmd
quuid command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL