Add user-defined tag naming#53
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.
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.
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.
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
defaulttag (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.