About this project

go-branded-id is a Go library that provides branded, strongly-typed identifiers. It uses phantom types to prevent mixing different entity IDs (e.g., UserID vs OrderID) at compile time, catching bugs that would otherwise go unnoticed. The library is zero-allocation for core operations, uses only the Go standard library, and supports full serialization including JSON, SQL, Text, Binary, and Gob. It works with any comparable type, offers zero-value semantics (serializes to null in JSON, nil in SQL), and includes a SQL scanner/valuer. Named brand types can provide a Name() method for debug-visible strings and brand-aware validation. The library also provides sentinel errors for error handling and a codemod tool to generate Name() stubs. It requires Go 1.26+.