Closed hohmannr closed 11 months ago
Patch coverage: 100.00
% and project coverage change: +0.09
:tada:
Comparison is base (
04f3781
) 88.95% compared to head (b102547
) 89.04%.
:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
The idea is great, but not sure how you will handle the maintainability and readability of your application later. How will your team understand you're using this library with the custom tag?
That is a very good question. We have solved this issue with another package, here goes the story: We have lightweight wrappers around multiple packages, which set them up to our needs. E.g. configuring them in an init()
function. We use go playground validator for payload validation with custom functions and the convention is to prefix all custom validation functions with _
e.g. _rfc3339
for custom timestamps in RFC3339 format. In Code it looks like this:
type UserInfo struct {
FirstName string `validate_gateway:"required,max=256" validate_api:"required,max=256"`
LastName string `validate_gateway:"required,max=256" validate_api:"required,max=256"`
Source string `validate_gateway:"eq=gateway" validate_api:"eq=api"`
Timestamp string `validate_gateway:"_rfc3339" validate_api:"_rfc3339"`
}
The same strategy can be used for faker
to generate testdata. Currently we have a testutil.go
file, which has functions like func TestdataUserInfoGateway(t testing.TB) *UserInfo
that generate the testdata, if faker
supports multiple custom tags, we can get rid of about 60+ functions like this. Here is an example of how it would look like with faker:
type UserInfo struct {
FirstName string `faker_gateway:"first_name" faker_api:"first_name"`
LastName string `faker_gateway:"last_name" faker_api:"last_name"`
Source string `faker_gateway:"_source_gateway" faker_api:"_source_api"`
Timestamp string `faker_gateway:"_rfc3339" faker_api:"_rfc3339"`
}
Hey @bxcodec! Hope you are fine! Just wanted to quickly check the status on this PR?
This would solve the problem described in #27.
I have added the ability to change the default tag name to a custom one, which is configurable via an
options.OptionFunc
. I tried to be minimal invasive and have added a test to cover the custom tag case and an example file, so people can find this feature in go.pkg reference and the github repo.