Struct Data Fake Generator
Faker will generate you a fake data based on your Struct.
You can file an Issue. See documentation in Go.Dev
go get -u github.com/go-faker/faker/v4
- Using Struct's tag:
- Custom Struct's tag (define your own faker data): example_custom_faker_test.go
- Without struct's tag: example_without_tag_test.go
- Single Fake Data Function: example_single_fake_data_test.go
- custom struct type providers : example_custom_struct_test.go
- large nested (& circular) struct with map & slice size limits & depth limitations : example_with_limits_test.go
Bench To Generate Fake Data
BenchmarkFakerDataNOTTagged-4 500000 3049 ns/op 488 B/op 20 allocs/op
BenchmarkFakerDataTagged-4 100000 17470 ns/op 380 B/op 26 allocs/op
The Struct Field must be PUBLIC.
Support For :
- pointer fields of any type
int
,int8
,int16
,int32
&int64
uint
,uint8
,uint16
,uint32
&uint64
bool
string
float32
,float64
- struct & nested struct
slice
/array
of any typemap
of any key/value of supported types- custom struct types by registering a
StructTypeProvider
& implementing your own generator function. This can be used for redefined time, big.Rat, etc. See example for usage.- default
time.Time
provider is registered, you can override it by registering your own provider.
- default
Unfortunately this library has some limitation
- It does not support private fields. Make sure your structs fields you intend to generate fake data for are public, it would otherwise trigger a panic. You can however omit fields using a tag skip
faker:"-"
on your private fields. - It does not support the
interface{}
data type. How could we generate anything without knowing its data type? - It does not support the
map[interface{}]interface{}
,map[any_type]interface{}
&map[interface{}]any_type
data types. Once again, we cannot generate values for an unknown data type. - Some extra custom types can be supported IF AND ONLY IF extended with AddProvider() please see example
- The
oneof
tag currently only supportsstring
, theint
types, and bothfloat32
&float64
. Further support is coming soon (i.e. hex numbers, etc). See example for usage.
To contrib to this project, you can open a PR or an issue.