|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Repository Overview |
| 6 | + |
| 7 | +This is the faker library for Go - a data generation library for creating fake/mock data for testing, database seeding, and anonymization. It's heavily inspired by PHP's Faker. |
| 8 | + |
| 9 | +The library requires Go >= 1.22 (as per go.mod) and uses Go's math/rand/v2 package for random generation. |
| 10 | + |
| 11 | +## Core Architecture |
| 12 | + |
| 13 | +The library follows a modular design where each data type has its own file and corresponding test file: |
| 14 | +- `faker.go` - Main Faker struct and GeneratorInterface that provides thread-safe random generation |
| 15 | +- Each data category (e.g., `person.go`, `address.go`, `internet.go`) implements its own struct with methods |
| 16 | +- All generators are accessed through the main Faker instance created with `faker.New()` |
| 17 | +- The library uses struct tags (`fake:"..."`) to support generating fake data directly into structs |
| 18 | + |
| 19 | +Key pattern: Each generator returns a new instance that shares the same underlying random generator for consistency and thread safety. |
| 20 | + |
| 21 | +## Common Commands |
| 22 | + |
| 23 | +### Testing |
| 24 | +```bash |
| 25 | +# Run all tests |
| 26 | +go test ./... |
| 27 | + |
| 28 | +# Run tests with verbose output |
| 29 | +go test -v ./... |
| 30 | + |
| 31 | +# Run tests with benchmarks |
| 32 | +go test -v -bench=. ./... |
| 33 | + |
| 34 | +# Run a specific test |
| 35 | +go test -run TestPersonName -v |
| 36 | + |
| 37 | +# Run tests multiple times (as done in CI) |
| 38 | +for i in 1 2 3; do go test -v -bench=. ./... && break || if [ $i -eq 3 ]; then exit 1; fi; done |
| 39 | +``` |
| 40 | + |
| 41 | +### Code Quality |
| 42 | +```bash |
| 43 | +# Format code |
| 44 | +gofmt -w . |
| 45 | + |
| 46 | +# Check for issues |
| 47 | +go vet ./... |
| 48 | + |
| 49 | +# Build the library |
| 50 | +go build ./... |
| 51 | +``` |
| 52 | + |
| 53 | +Note: There are known struct tag syntax issues in `struct_test.go` (lines 239, 248, 274) that cause `go vet` warnings. These are intentional test cases for malformed tags. |
| 54 | + |
| 55 | +## Development Workflow |
| 56 | + |
| 57 | +1. The library is purely functional with no external dependencies beyond Go standard library |
| 58 | +2. Each data generator should have comprehensive tests in its corresponding `_test.go` file |
| 59 | +3. Thread safety is handled at the Faker struct level through the threadSafeRand wrapper |
| 60 | +4. When adding new generators, follow the existing pattern of creating a new struct type with methods |
| 61 | +5. The main branch is `master` (not `main`) |
0 commit comments