-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add user-defined tag naming #53
base: master
Are you sure you want to change the base?
Conversation
These changes allow the caller to define a custom tag name, either globally or locally to a function call.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #53 +/- ##
==========================================
- Coverage 95.97% 86.14% -9.83%
==========================================
Files 2 2
Lines 149 166 +17
==========================================
Hits 143 143
- Misses 3 19 +16
- Partials 3 4 +1 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
Alternatively, you could also just call I can write additional tests if you let me know if the current implementation is ideal or if you want it wrapped like that. |
I also realized the |
FWIW, looks like the most recent circleci test failed was due to linting; it doesn't like that the block-commented example output isn't indented an additional level. (Edit: whoops, didn't mean to close) |
Name string `default:"John Smith"` | ||
Age int `default:"27"` | ||
Gender Gender `default:"m"` | ||
Name string `default:"John Smith" default_alt:"Jane Doe"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you please revert these changes?
"User-Definable tag name" should not be this library's primary use case.
The same goes for example/main.go — Although it might be useful to have a separate file.
// SetWithTag initializes members in a struct referenced by a pointer using an explicit tag name. | ||
// Maps and slices are initialized by `make` and other primitive types are set with default values. | ||
// `ptr` should be a struct pointer | ||
func SetWithTag(ptr interface{}, runtimeTag string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: runtimeTag
sounds a bit off to me. Reflection at its essence is about runtime.
tagName
should suffice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd also like to add minimum specs for testing user-specified tag names.
Do note that we don't want to extend the existing struct; create a new struct to test with.
Frequently, many other libraries use a
default
tag (off the top of my head, https://github.com/jessevdk/go-flags does but I'm sure there are others.)These changes allow the caller to define a custom tag name, either globally or locally to a function call, to avoid runtime conflicts with these other libraries.
These changes are 100% backwards-compatible, no changes to exported API have been made and all existing consuming code will function as it did before.