Documentation
¶
Overview ¶
Package faker provides deterministic fake data generators for use with seedling's Generate option. All methods derive output solely from the wrapped *rand.Rand, ensuring reproducible test data when the same seed is used.
Basic usage with seedling.Generate:
seedling.Generate(func(r *rand.Rand, u *User) {
f := faker.New(r)
u.Name = f.Name()
u.Email = f.Email()
})
Faker is NOT safe for concurrent use.
Index ¶
- func Pick[T any](f *Faker, items []T) T
- type Faker
- func (f *Faker) Address() string
- func (f *Faker) Bool() bool
- func (f *Faker) City() string
- func (f *Faker) Country() string
- func (f *Faker) CreditCard() string
- func (f *Faker) Date() time.Time
- func (f *Faker) DateBetween(from, to time.Time) time.Time
- func (f *Faker) Email() string
- func (f *Faker) FirstName() string
- func (f *Faker) Float() float64
- func (f *Faker) FloatBetween(min, max float64) float64
- func (f *Faker) HexColor() string
- func (f *Faker) IPv4() string
- func (f *Faker) Int() int
- func (f *Faker) IntBetween(min, max int) int
- func (f *Faker) LastName() string
- func (f *Faker) Name() string
- func (f *Faker) Paragraph() string
- func (f *Faker) Phone() string
- func (f *Faker) Sentence() string
- func (f *Faker) URL() string
- func (f *Faker) UUID() string
- func (f *Faker) Username() string
- func (f *Faker) Word() string
- func (f *Faker) ZipCode() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Faker ¶
type Faker struct {
// contains filtered or unexported fields
}
Faker generates deterministic fake data from a *rand.Rand source.
func Default ¶
func Default() *Faker
Default creates a Faker with a non-deterministic seed. Use New with a fixed seed for reproducible tests.
func New ¶
New creates a Faker backed by the given RNG with the default "en" locale. Passing the *rand.Rand from seedling.Generate ensures deterministic output. It panics if r is nil.
Example ¶
f := faker.New(rand.New(rand.NewPCG(42, 42))) fmt.Println(f.Name()) fmt.Println(f.Email()) fmt.Println(f.Phone()) fmt.Println(f.Address()) fmt.Println(f.UUID())
Output: Cynthia Torres kathleen.roberts@local.test +1-339-323-7574 8197 North St 5171f6ef-7782-4870-83f6-83d1b4fa890c
func NewWithLocale ¶ added in v0.2.0
NewWithLocale creates a Faker backed by the given RNG with the specified locale. Supported locales: "en", "ja", "zh", "ko", "de", "fr". It panics if r is nil or the locale is unknown.
func (*Faker) City ¶
City returns a random city name.
Example ¶
f := faker.New(rand.New(rand.NewPCG(1, 1))) fmt.Println(f.City())
Output: Detroit
func (*Faker) CreditCard ¶
CreditCard returns a random credit card number in XXXX-XXXX-XXXX-XXXX format.
func (*Faker) DateBetween ¶
DateBetween returns a random time between from and to (inclusive). It panics if from is after to.
func (*Faker) Email ¶
Email returns a random email address. For non-Latin locales, romanized names are used to produce valid ASCII addresses.
func (*Faker) FloatBetween ¶
FloatBetween returns a random float64 in [min, max).
func (*Faker) IntBetween ¶
IntBetween returns a random int in [min, max]. It panics if min > max.
func (*Faker) Name ¶
Name returns a random full name. For CJK locales (ja, zh, ko), the name is formatted as LastFirst (no space).