go.uuid

Pure Go implementation of RFC 4122 UUIDs (versions 1, 2, 3, 4, and 5) with parsing, string formatting, and database/sql integration built in.

Library
Go
vv1.2.0
4,901stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
43/100Fair
Development Activity0
Maintenance0
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
55/100Fair
Architecture70
Code Quality55
Innovation40
Learning Curve55

go.uuid is a dependency-free Go package for creating and parsing Universally Unique Identifiers as defined by RFC 4122. It implements all five standard UUID versions — timestamp+MAC-based (V1), DCE Security POSIX UID/GID-based (V2), MD5-hash-based (V3), cryptographically random (V4), and SHA-1-hash-based (V5) — behind a single UUID type backed by a fixed 16-byte array.

Beyond generation, the package handles the full round-trip: parsing UUIDs from canonical, hyphen-less, braced, and URN string forms, marshaling to and from text and binary representations, and implementing database/sql’s driver.Valuer/Scanner interfaces (including a NullUUID wrapper) so a UUID field can be read from and written to a SQL column with no extra glue code. It was one of the earliest widely-adopted Go UUID libraries and predates Go modules — the package has no go.mod and is fetched as a classic GOPATH import path.

What You Get

  • A UUID type ([16]byte) with NewV1/NewV2/NewV3/NewV4/NewV5 generator functions covering every RFC 4122 and DCE 1.1 version
  • String parsing via FromString/FromBytes (and OrNil variants) supporting canonical, hash-like, braced, and URN UUID formats
  • encoding.TextMarshaler/TextUnmarshaler and encoding.BinaryMarshaler/BinaryUnmarshaler implementations for JSON, config, and wire-format use
  • database/sql driver.Valuer/Scanner support plus a NullUUID wrapper for nullable UUID columns
  • Predefined namespace UUIDs (NamespaceDNS, NamespaceURL, NamespaceOID, NamespaceX500) for V3/V5 name-based generation

Common Use Cases

  • Generating primary keys or correlation IDs for database rows and log entries
  • Producing deterministic, name-based IDs (V3/V5) for the same logical entity across services
  • Reading and writing UUID columns directly through database/sql without a custom scan/value shim
  • Parsing UUIDs received from external APIs or config files in whatever string format they arrive in

Under The Hood

Architecture The package is a single flat uuid package split by concern across four files rather than sub-directories: uuid.go defines the core [16]byte UUID type plus version/variant bit manipulation and the Must helper; generator.go defines a Generator interface and its default rfc4122Generator implementation, exposed through a package-level singleton (global) whose clock sequence and hardware address are lazily initialized once via sync.Once and guarded by a mutex for concurrent generation; codec.go handles parsing and (un)marshaling across canonical, hash-like, braced, and URN string forms plus binary encoding; and sql.go adds database/sql driver.Valuer/Scanner support via a thin NullUUID wrapper. There is no dependency-injection layer or internal package boundary — every file operates directly on the shared UUID array type, so any change to that underlying representation (e.g. its byte layout) would ripple through all four files at once.

Tech Stack go.uuid has zero third-party runtime dependencies — it only imports the Go standard library (crypto/rand, crypto/md5, crypto/sha1, encoding/hex, encoding/binary, database/sql/driver, net, sync, time, os). It predates Go modules entirely (no go.mod in the repo) and was built and tested via Travis CI against Go 1.6 through tip using classic GOPATH-style go get installs. Its only integration point with a larger framework is the standard database/sql package, which it hooks into directly rather than depending on any particular ORM or driver.

Code Quality Testing combines the standard testing package with gopkg.in/check.v1 (gocheck) for BDD-style assertions, spread across four test files (roughly 730 lines) covering the codec, generator, sql, and core uuid paths, with the README claiming full statement coverage. Error handling is explicit throughout — generation and parsing functions return errors rather than swallowing them, and panics are isolated to the opt-in Must helper. Naming follows idiomatic Go conventions and exported symbols carry doc comments, but there is no linter or go vet step in CI (only coverage reporting), and the lack of a go.mod means it sits outside modern Go’s module-aware tooling and version resolution.

What Makes It Unique go.uuid’s distinguishing trait is breadth over novelty: it implements all five RFC 4122/DCE 1.1 UUID versions — including the less commonly implemented V2 (DCE Security, POSIX UID/GID-based) — behind one small, dependency-free type, plus first-class database/sql integration out of the box. It does not introduce new algorithmic techniques beyond the RFC-specified ones, but as one of the earliest and most widely adopted Go UUID packages (predating Go modules), it played a formative role in the ecosystem that later community forks and alternatives built on.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search