Documentation
¶
Overview ¶
Package identifier defines contracts shared by concrete identifier families.
Index ¶
- Variables
- type Clock
- type ClockFunc
- type Family
- type Generator
- type ID
- func (id ID[Tag]) Compare(other ID[Tag]) int
- func (id ID[Tag]) IsZero() bool
- func (id ID[Tag]) LogValue() slog.Value
- func (id ID[Tag]) MarshalBinary() ([]byte, error)
- func (id ID[Tag]) MarshalJSON() ([]byte, error)
- func (id ID[Tag]) MarshalText() ([]byte, error)
- func (id *ID[Tag]) Scan(src any) error
- func (id ID[Tag]) String() string
- func (id *ID[Tag]) UnmarshalBinary(data []byte) error
- func (id *ID[Tag]) UnmarshalJSON(data []byte) error
- func (id *ID[Tag]) UnmarshalText(text []byte) error
- func (id ID[Tag]) Value() (driver.Value, error)
- type Inspection
- type Validator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalid reports malformed, non-canonical, or disallowed input. ErrInvalid = errors.New("invalid identifier") // ErrEntropy reports failure while acquiring random bytes. ErrEntropy = errors.New("identifier entropy failure") // ErrClockRollback reports a clock moving behind supported generator state. ErrClockRollback = errors.New("identifier clock rollback") // ErrOverflow reports exhausted monotonic or sequence space. ErrOverflow = errors.New("identifier sequence overflow") // ErrUnsupported reports a valid but unsupported identifier feature. ErrUnsupported = errors.New("unsupported identifier") )
Functions ¶
This section is empty.
Types ¶
type Family ¶
type Family string
Family identifies an encoding without implying equivalent guarantees.
const ( // FamilyUUID identifies RFC UUID values. FamilyUUID Family = "uuid" // FamilyULID identifies canonical ULID values. FamilyULID Family = "ulid" // FamilyTypeID identifies TypeID values. FamilyTypeID Family = "typeid" // FamilyKSUID identifies Segment-compatible KSUID values. FamilyKSUID Family = "ksuid" // FamilyNanoID identifies configured NanoID values. FamilyNanoID Family = "nanoid" )
type ID ¶
type ID[Tag Validator] struct { // contains filtered or unexported fields }
ID is a strongly typed canonical identifier. Different Tag arguments are distinct Go types and cannot be mixed without an explicit conversion.
Example ¶
package main
import (
identifier "github.com/faustbrian/go-identifier"
identifieruuid "github.com/faustbrian/go-identifier/uuid"
)
func main() {
// Domain tags validate canonical family text without reflection or a
// runtime registry. See the package documentation for a complete tag.
var _ identifier.Generator[identifieruuid.ID] = identifieruuid.NewV4Generator(nil)
}
Output:
func (ID[Tag]) LogValue ¶
LogValue redacts the identifier from structured logs. Callers must opt in explicitly with String when an identifier has been approved for logging.
func (ID[Tag]) MarshalBinary ¶
MarshalBinary uses canonical text so typed values remain family-neutral.
func (ID[Tag]) MarshalJSON ¶
MarshalJSON encodes the canonical identifier as a JSON string.
func (ID[Tag]) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*ID[Tag]) UnmarshalBinary ¶
UnmarshalBinary validates canonical text.
func (*ID[Tag]) UnmarshalJSON ¶
UnmarshalJSON decodes and validates a canonical JSON string.
func (*ID[Tag]) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Inspection ¶
Inspection exposes only properties actually defined by an identifier family.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package idtest provides deterministic clocks, entropy, and reusable identifier assertions.
|
Package idtest provides deterministic clocks, entropy, and reusable identifier assertions. |
|
Package ksuid implements canonical, interoperable KSUIDs with explicitly owned clock, entropy, and optional same-second monotonic state.
|
Package ksuid implements canonical, interoperable KSUIDs with explicitly owned clock, entropy, and optional same-second monotonic state. |
|
Package nanoid implements compact random identifiers with configurable, bias-free ASCII alphabets and a mandatory 120-bit entropy floor.
|
Package nanoid implements compact random identifiers with configurable, bias-free ASCII alphabets and a mandatory 120-bit entropy floor. |
|
Package slug provides deterministic compatibility profiles for identifiers derived from human-readable text.
|
Package slug provides deterministic compatibility profiles for identifiers derived from human-readable text. |
|
Package typeid implements the TypeID specification version 0.3.0 with canonical prefixes, strict Base32, and UUIDv7-backed generation.
|
Package typeid implements the TypeID specification version 0.3.0 with canonical prefixes, strict Base32, and UUIDv7-backed generation. |
|
Package ulid implements canonical ULIDs with explicitly owned monotonic generation state compatible with existing 26-character ULID storage.
|
Package ulid implements canonical ULIDs with explicitly owned monotonic generation state compatible with existing 26-character ULID storage. |
|
Package uuid implements canonical RFC 9562 UUID parsing and v4/v7 generation with explicitly owned entropy, clocks, and monotonic state.
|
Package uuid implements canonical RFC 9562 UUID parsing and v4/v7 generation with explicitly owned entropy, clocks, and monotonic state. |