faker
faker copied to clipboard
Make possible to ignore some fields or provide custom generators
For the cases when you cant use struct tags (eg struct is from 3d-party) it would be nice to have an option to ignore some fields by it's name or provide a custom generator.
type SomeType struct {
Field1 error
Field2 context.Context
Field3 string
}
a.
var v SomeType
faker.Fake(&v, faker.IgnoreFields("Field1", "Field2"))
b.
var v SomeType
faker.Fake(&v,
faker.FieldGenerator("Field1", func() (interface{}, error) {
return context.TODO(), nil
}),
faker.FieldGenerator("Field2", func() (interface{}, error){
return errors.New("test"), nil
},
)
c.
faker.SetGeneratorForType("context.Context", func() (interface{}, error) {
return context.TODO(), nil
})
faker.SetGeneratorForType("error", func() (interface{}, error) {
return errors.New("test"), nil
})
b
and c
are more flexible as they allow custom generators
Hi @unkeep Can we link this feature with the current custom tag generator here?
https://github.com/bxcodec/faker/blob/72e522332c49399d4c52a9ad8086244df95f38a6/faker.go#L405-L456
fixed in #160
Let me know if it still not enough