Conversation
|
Ah it looks like IsExported() needs go >= 1.17. I could just check the case of the first char of the field? |
|
See golang/go#41563, basically you'll want to check if |
|
|
||
| for i := 0; i < t.NumField(); i++ { | ||
| if defaultVal := t.Field(i).Tag.Get(fieldName); defaultVal != "-" { | ||
| if t.Field(i).IsExported() { |
There was a problem hiding this comment.
if t.Field(i).IsExported() {
// Check whether the field is exported
if t.Field(i).PkgPath == "" {
There was a problem hiding this comment.
@servusdei2018 your suggestion appears to be incorrect:
There was a problem hiding this comment.
my bad, thanks for catching that! fixed it
I would utilize https://pkg.go.dev/encoding/json#Unmarshaler or https://pkg.go.dev/encoding#TextUnmarshaler interfaces instead. |
|
This PR is breaking this promise: |
Hey there! I'd love to be able to set a custom default for a type based on the tag like so:
This PR adds the interface and modifies the Set() logic to use it. Added tests to account for success and failure. All tests passing. Thanks!