Documentation
¶
Overview ¶
Package typeid implements the TypeID specification version 0.3.0 with canonical prefixes, strict Base32, and UUIDv7-backed generation.
Index ¶
- func ValidatePrefix(prefix string) error
- type Generator
- type ID
- func (id ID) Bytes() [16]byte
- func (id ID) Compare(other ID) int
- func (id ID) Inspect() identifier.Inspection
- func (id ID) IsZero() bool
- func (id ID) LogValue() slog.Value
- func (id ID) MarshalBinary() ([]byte, error)
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) MarshalText() ([]byte, error)
- func (id ID) Prefix() string
- 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 UUIDSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidatePrefix ¶
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.
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 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 ¶
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) Inspect ¶
func (id ID) Inspect() identifier.Inspection
Inspect reports the suffix version and UUIDv7 timestamp when present.
func (ID) MarshalBinary ¶
MarshalBinary encodes canonical text because the prefix is part of a TypeID.
func (ID) MarshalJSON ¶
MarshalJSON encodes canonical text, including the canonical zero TypeID.
func (ID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*ID) UnmarshalBinary ¶
UnmarshalBinary validates canonical text.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON decodes canonical text and accepts null as the zero TypeID.
func (*ID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type UUIDSource ¶
type UUIDSource interface {
string | identifieruuid.ID
}
UUIDSource is a canonical UUID string or a validated identifier UUID.