idgen

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 4 Imported by: 0

README

idgen — pluggable ID generation

idgen provides composable ID generators. The ecosystem default is UUIDv7 (RFC 9562): time-sortable, globally unique, and friendly to B-Tree indexes.

Quick start

id := idgen.New()                                  // UUIDv7: "019513ab-..."
id = idgen.Prefixed("dos_", idgen.Default)()       // "dos_019513ab-..."
id = idgen.NanoID(8)()                             // "a3f8k2p1"
id = idgen.Timestamped(idgen.NanoID(6))()          // "20260221T120000Z_abc123"

parsed, err := idgen.Parse("019513ab-89ab-7cde-...")

Strategies

Generator Output Use case
UUIDv7() 019513ab-89ab-7cde-8f01-... Default, time-sortable
NanoID(n) a3f8k2p1 Short, ephemeral (session IDs)
Prefixed(p, gen) aud_019513ab-... Domain-scoped IDs
Timestamped(gen) 20260221T120000Z_abc Human-readable time prefix

Ecosystem conventions

Prefix Domain
aud_ Audit entries
evt_ Business events
dos_ Dossiers
req_ HTTP requests
tus_ Resumable uploads

Exported API

Symbol Description
Generator func() string
Default Ecosystem default (UUIDv7())
New() Generate one ID with Default
UUIDv7() RFC 9562 generator
NanoID(length) Base-36 random generator
Prefixed(prefix, gen) Add prefix to any generator
Timestamped(gen) Add ISO 8601 timestamp prefix
Parse(s) / MustParse(s) UUID validation

Documentation

Overview

Package idgen provides pluggable ID generation for the HOROS ecosystem.

All constructors across pkg/ (audit, mcprt, mcpquic) accept a Generator, making the ID strategy a startup-time decision rather than a compile-time one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustParse

func MustParse(s string) string

MustParse validates a UUID string and returns it or panics.

func New

func New() string

New produces an ID using the Default generator.

func Parse

func Parse(s string) (string, error)

Parse validates a UUID string and returns it or an error.

Types

type Generator

type Generator func() string

Generator produces unique string identifiers.

var Default Generator = UUIDv7()

Default is the ecosystem default: UUIDv7 (RFC 9562). Time-sortable, globally unique. Prefixed variants should compose on top.

func NanoID

func NanoID(length int) Generator

NanoID returns a Generator that produces base-36 IDs of the given length. This is the lightweight strategy — short, URL-safe, fast. Use only where UUIDv7 is too verbose (e.g. session tokens, short-lived keys).

func Prefixed

func Prefixed(prefix string, gen Generator) Generator

Prefixed wraps a Generator and prepends a fixed prefix to every ID. Useful for type-scoped identifiers (e.g. "aud_", "sess_", "trc_").

func Timestamped

func Timestamped(gen Generator) Generator

Timestamped returns a Generator that produces IDs in the format "20060102T150405Z_<suffix>" where suffix comes from the inner generator.

func UUIDv7

func UUIDv7() Generator

UUIDv7 returns a Generator that produces RFC 9562 UUID v7 strings. Time-sortable, globally unique, ecosystem convention per CLAUDE.md.

Jump to

Keyboard shortcuts

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