Discover Packages
github.com/hazyhaar/pkg
idgen
package
Version:
v0.1.0
Opens a new window with list of versions in this module.
Published: Mar 1, 2026
License: MIT
Opens a new window with license information.
Imports: 4
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
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
Expand ▾
Collapse ▴
Documentation
¶
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.
MustParse validates a UUID string and returns it or panics.
New produces an ID using the Default generator.
Parse validates a UUID string and returns it or an error.
Generator produces unique string identifiers.
Default is the ecosystem default: UUIDv7 (RFC 9562 ).
Time-sortable, globally unique. Prefixed variants should compose on top.
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).
Prefixed wraps a Generator and prepends a fixed prefix to every ID.
Useful for type-scoped identifiers (e.g. "aud_", "sess_", "trc_").
Timestamped returns a Generator that produces IDs in the format
"20060102T150405Z_<suffix>" where suffix comes from the inner generator.
UUIDv7 returns a Generator that produces RFC 9562 UUID v7 strings.
Time-sortable, globally unique, ecosystem convention per CLAUDE.md.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.