Documentation
¶
Index ¶
- type DefaultFaker
- func (f *DefaultFaker) Address() string
- func (f *DefaultFaker) Bool() bool
- func (f *DefaultFaker) City() string
- func (f *DefaultFaker) Country() string
- func (f *DefaultFaker) Date() time.Time
- func (f *DefaultFaker) DateBetween(start, end time.Time) time.Time
- func (f *DefaultFaker) Email() string
- func (f *DefaultFaker) FirstName() string
- func (f *DefaultFaker) Float64Between(min, max float64) float64
- func (f *DefaultFaker) IntBetween(min, max int) int
- func (f *DefaultFaker) LastName() string
- func (f *DefaultFaker) Name() string
- func (f *DefaultFaker) Paragraph() string
- func (f *DefaultFaker) Phone() string
- func (f *DefaultFaker) Pick(items []string) string
- func (f *DefaultFaker) Sentence() string
- func (f *DefaultFaker) UUID() string
- func (f *DefaultFaker) Word() string
- type Factory
- type Faker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultFaker ¶
type DefaultFaker struct {
// contains filtered or unexported fields
}
DefaultFaker implements the Faker interface using a seeded random source.
func NewFaker ¶
func NewFaker(seed int64) *DefaultFaker
NewFaker creates a new DefaultFaker with the given seed for reproducibility.
func NewFakerWithRand ¶
func NewFakerWithRand(rng *mathrand.Rand) *DefaultFaker
NewFakerWithRand creates a new DefaultFaker using the provided *math/rand.Rand.
func (*DefaultFaker) Address ¶
func (f *DefaultFaker) Address() string
func (*DefaultFaker) Bool ¶
func (f *DefaultFaker) Bool() bool
func (*DefaultFaker) City ¶
func (f *DefaultFaker) City() string
func (*DefaultFaker) Country ¶
func (f *DefaultFaker) Country() string
func (*DefaultFaker) Date ¶
func (f *DefaultFaker) Date() time.Time
func (*DefaultFaker) DateBetween ¶
func (f *DefaultFaker) DateBetween(start, end time.Time) time.Time
func (*DefaultFaker) Email ¶
func (f *DefaultFaker) Email() string
func (*DefaultFaker) FirstName ¶
func (f *DefaultFaker) FirstName() string
func (*DefaultFaker) Float64Between ¶
func (f *DefaultFaker) Float64Between(min, max float64) float64
func (*DefaultFaker) IntBetween ¶
func (f *DefaultFaker) IntBetween(min, max int) int
func (*DefaultFaker) LastName ¶
func (f *DefaultFaker) LastName() string
func (*DefaultFaker) Name ¶
func (f *DefaultFaker) Name() string
func (*DefaultFaker) Paragraph ¶
func (f *DefaultFaker) Paragraph() string
func (*DefaultFaker) Phone ¶
func (f *DefaultFaker) Phone() string
func (*DefaultFaker) Pick ¶
func (f *DefaultFaker) Pick(items []string) string
func (*DefaultFaker) Sentence ¶
func (f *DefaultFaker) Sentence() string
func (*DefaultFaker) UUID ¶
func (f *DefaultFaker) UUID() string
UUID generates a v4 UUID using crypto/rand for proper randomness.
func (*DefaultFaker) Word ¶
func (f *DefaultFaker) Word() string
type Factory ¶
type Factory[T any] struct { // contains filtered or unexported fields }
Factory is a generic builder for generating model instances with fake data. It supports a default definition, named states that override fields, and batch creation via MakeMany.
func NewFactory ¶
NewFactory creates a new Factory with the given definition function. A default Faker seeded from the current time is used.
func (*Factory[T]) Make ¶
func (f *Factory[T]) Make() T
Make creates a single instance using the definition, then applies any active states in the order they were added.
func (*Factory[T]) MakeMany ¶
MakeMany creates count instances. Each instance is independently generated through Make.
func (*Factory[T]) State ¶
State registers a named state modifier on the factory. The modifier receives the Faker and the base instance produced by the definition, and returns a modified instance. State returns the same factory for chaining.
type Faker ¶
type Faker interface {
// Name returns a full name (first + last).
Name() string
// FirstName returns a random first name.
FirstName() string
// LastName returns a random last name.
LastName() string
// Email returns a random email address.
Email() string
// Phone returns a random phone number string.
Phone() string
// Address returns a random street address.
Address() string
// City returns a random city name.
City() string
// Country returns a random country name.
Country() string
// UUID returns a random v4 UUID string.
UUID() string
// Paragraph returns a random paragraph of text.
Paragraph() string
// Sentence returns a random sentence.
Sentence() string
// Word returns a random word.
Word() string
// IntBetween returns a random integer in [min, max].
IntBetween(min, max int) int
// Float64Between returns a random float64 in [min, max).
Float64Between(min, max float64) float64
// Bool returns a random boolean.
Bool() bool
// Date returns a random date.
Date() time.Time
// DateBetween returns a random date between start and end.
DateBetween(start, end time.Time) time.Time
// Pick returns a random element from the given slice.
Pick(items []string) string
}
Faker defines the contract for generating fake data values. Implementations provide realistic-looking data for use in factories and seeders.