Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Tag Name #27

Open
hohmannr opened this issue Jun 14, 2023 · 2 comments
Open

Custom Tag Name #27

hohmannr opened this issue Jun 14, 2023 · 2 comments

Comments

@hohmannr
Copy link
Contributor

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
Copy link
Contributor Author

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

hohmannr added a commit to hohmannr/faker that referenced this issue Jun 14, 2023
Signed-off-by: hohmannr <raphael.hohmann@tuta.io>
hohmannr added a commit to hohmannr/faker that referenced this issue Jun 14, 2023
Signed-off-by: hohmannr <raphael.hohmann@tuta.io>
@bxcodec
Copy link
Contributor

bxcodec commented Jun 17, 2023

Left a comment in the PR

bxcodec pushed a commit that referenced this issue Jul 24, 2023
* feat: adds a changeable tag name (#27)

Signed-off-by: hohmannr <raphael.hohmann@tuta.io>

* chore: refactors ErrTagNameInvalid to ErrFieldTagIdentifierInvalid

---------

Signed-off-by: hohmannr <raphael.hohmann@tuta.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants