go-faker / faker

Go (Golang) Fake Data Generator for Struct, previously https://github.com/bxcodec/faker
https://pkg.go.dev/github.com/go-faker/faker/v4
MIT License
614 stars 30 forks source link

Custom Tag Name #27

Open hohmannr opened 1 year ago

hohmannr commented 1 year ago

I am running currently into the following problem: I am trying to generate different fake data for different API endpoints, that revolve around the same data object, where the data object looks slightly different, depending from which endpoint it was created.

Example

type Data struct {
    Source string `faker:"source"`
    // ...
}

source is a custom tag, that returns a hard-coded string like "Gateway" or "InternalAPI". Since this string varies, I cannot easily generate custom fake data for all the sources. This would be solved if one could set the tag name when generating the data, ergo:

type Data struct {
    Source string `faker_api:"source_api" faker_gateway:"source_gateway"`
    // ...
}

The ability to set a custom tag name via the options.OptionFunc would be ideal to solve this use-case.

hohmannr commented 1 year ago

I have added a PR for this, check: #28

bxcodec commented 1 year ago

Left a comment in the PR