Gofakeit
A zero-dependency Go library with 310+ functions for generating random fake data, from single values to fully populated structs.
Repository Health
Technical Analysis
Gofakeit is a random data generator for Go, covering hundreds of real-world categories — names, addresses, companies, credit cards, beer, hacker phrases, Minecraft items, and more — behind a simple global API (gofakeit.Name(), gofakeit.Email()) that requires no setup. It also provides a reflection-driven Struct() function that populates an entire struct’s exported fields in one call, using fake:"{firstname}"-style struct tags to control what each field gets, including nested structs, slices, maps, and custom regex patterns.
For callers who need more than the convenience API, Gofakeit exposes an instance-based Faker type created via New()/NewFaker(), letting tests seed reproducible output or plug in alternate random sources (crypto/rand, JSF, SFC, or a simple incrementing counter) without touching the package-level global. A companion CLI (cmd/gofakeit) and HTTP server (cmd/gofakeitserver) expose the same 310+ generators outside of Go code, useful for scripting or seeding data from other languages.
The library has zero external dependencies, targets Go 1.22+ to use math/rand/v2, and ships with an almost 1:1 ratio of test files to source files, making it a common choice for seeding local databases, generating mock API responses, and filling test fixtures.
What You Get
- 310+ generator functions grouped by real-world domain: person, address, company, payment, internet, beer, hacker-speak, Minecraft, and dozens more
- A reflection-based
Struct()function that fills every exported field of a struct in one call, driven byfake:"{...}",fakesize:"...", andformat:"..."struct tags - A
Fakertype for isolated, seedable, thread-safe generation, alongside the simpler package-level global functions for one-off calls - Pluggable random sources (PCG, ChaCha8, crypto/rand, JSF, SFC, and a deterministic “dumb” counter) via the
sourcesub-package - A
Fakeableinterface for extending Gofakeit with custom generation logic on user-defined types - A standalone CLI (
cmd/gofakeit) and HTTP server (cmd/gofakeitserver) that expose every generator function outside of Go code
Common Use Cases
- Populating test fixtures and table-driven test cases with realistic random values instead of hand-written literals
- Seeding local or staging databases with believable sample data for development and demos
- Generating mock API responses for frontend development before a real backend exists
- Fuzzing or property-based testing where structs need to be filled with varied random data automatically
- Producing sample CSV/JSON/XML/SQL datasets for load testing or demoing data pipelines
Under The Hood
Architecture
Gofakeit is a single flat package (no internal/ layering) with one file per data domain — person.go, address.go, animal.go, and dozens more — each defining exported generator functions. Every generator has two forms: a package-level function that delegates to a GlobalFaker singleton, and a method on the Faker struct (faker.go) that holds a rand.Source and an optional mutex for thread safety, giving callers a choice between zero-setup global calls and isolated, seedable instances. Struct population (struct.go) uses reflect.Type/reflect.Value to recursively walk exported fields up to a configurable RecursiveDepth, dispatching generation based on fake, fakesize, and format struct tags. A central function-name registry (lookup.go/generate.go) maps generator names to implementations by string, and this registry is the one abstraction the rest of the system depends on — it backs the CLI, the HTTP server, and the struct-tag templating engine simultaneously, so changing its shape would ripple through all three.
Tech Stack
The module targets Go 1.22+ specifically to use math/rand/v2’s PCG generator as the default random source, and declares zero external dependencies in go.mod. A source sub-package supplies alternate rand.Source implementations — crypto/rand, ChaCha8, JSF (Jenkins Small Fast), SFC (Simple Fast Counter), and a deterministic incrementing “dumb” source — for callers who need different performance, security, or reproducibility tradeoffs. Two optional binaries under cmd/ (a CLI and an HTTP server) are built entirely on the standard library (flag, net/http), with no web framework. CI is a single GitHub Actions workflow running go test on every push.
Code Quality
Test coverage is unusually thorough for a Go library — 61 _test.go files against 60 non-test .go files, close to a 1:1 ratio, with dedicated coverage for concurrency (thread-safety under the Faker’s mutex) and the Fakeable extension interface. Tests use the standard testing package with benchmark functions feeding a generated BENCHMARKS.md. Error handling in reflection-heavy code paths (struct.go, faker.go’s Seed()) returns typed errors rather than panicking. There’s no dedicated linter configuration beyond go vet/gofmt convention and CI’s test run — solid but not maximal static-analysis tooling.
API Design
The defining DX choice is the dual API: every one of the 310+ generators is callable as a zero-argument global function (gofakeit.Email()) for quick use, or as a method on an explicit Faker instance for tests that need seeding or isolation — no wrapper boilerplate either way. The standout feature is Struct(), which populates a whole struct in one call using tag-driven rules (fake:"{firstname}", fakesize:"2,6", format:"2006-01-02"), supporting nested/embedded structs, slices, maps, custom regex-generated strings, and a Fakeable interface for fully custom field logic — a meaningfully more capable pattern than the typical single-value fake-data helper.