typeid

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package typeid implements the TypeID specification version 0.3.0 with canonical prefixes, strict Base32, and UUIDv7-backed generation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidatePrefix

func ValidatePrefix(prefix string) error

ValidatePrefix enforces the TypeID 0.3.0 prefix grammar.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator owns a prefix and UUIDv7 generator.

func NewGenerator

func NewGenerator(prefix string, generator *identifieruuid.V7Generator) (*Generator, error)

NewGenerator validates prefix and binds it to an owned UUIDv7 generator.

func (*Generator) New

func (generator *Generator) New() (ID, error)

New generates a UUIDv7-backed TypeID.

type ID

type ID struct {
	// contains filtered or unexported fields
}

ID is an immutable TypeID. Its Go zero value is the official unprefixed all-zero TypeID; the validity bit preserves every other prefix/value pair.

func FromBytes

func FromBytes(prefix string, value [16]byte) (ID, error)

FromBytes encodes any 128-bit value as permitted by the TypeID parser.

func FromUUID

func FromUUID[T UUIDSource](prefix string, value T) (ID, error)

FromUUID encodes any 128-bit UUID value with a validated prefix. String input permits the non-RFC versions and variants required by the TypeID spec.

func Parse

func Parse(text string) (ID, error)

Parse accepts only canonical TypeID 0.3.0 text. Parsing permits every 128-bit suffix required by the official vectors; generation remains UUIDv7.

func (ID) Bytes

func (id ID) Bytes() [16]byte

Bytes returns a copy of the 128-bit suffix value.

func (ID) Compare

func (id ID) Compare(other ID) int

Compare orders prefixes lexically and suffixes by unsigned bytes.

func (ID) Inspect

func (id ID) Inspect() identifier.Inspection

Inspect reports the suffix version and UUIDv7 timestamp when present.

func (ID) IsZero

func (id ID) IsZero() bool

IsZero reports whether the ID is the unprefixed all-zero TypeID.

func (ID) LogValue

func (id ID) LogValue() slog.Value

LogValue redacts the TypeID from structured logs.

func (ID) MarshalBinary

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

MarshalBinary encodes canonical text because the prefix is part of a TypeID.

func (ID) MarshalJSON

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

MarshalJSON encodes canonical text, including the canonical zero TypeID.

func (ID) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (ID) Prefix

func (id ID) Prefix() string

Prefix returns the validated type prefix.

func (*ID) Scan

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

Scan implements sql.Scanner for text and NULL.

func (ID) String

func (id ID) String() string

String returns canonical lowercase text, including the canonical zero ID.

func (*ID) UnmarshalBinary

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

UnmarshalBinary validates canonical text.

func (*ID) UnmarshalJSON

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

UnmarshalJSON decodes canonical text and accepts null as the zero TypeID.

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 driver.Valuer using canonical text.

type UUIDSource

type UUIDSource interface {
	string | identifieruuid.ID
}

UUIDSource is a canonical UUID string or a validated identifier UUID.

Jump to

Keyboard shortcuts

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