-
Notifications
You must be signed in to change notification settings - Fork 69
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
set default values of fields of a pointer type field #18
Conversation
And add go.mod |
Codecov Report
@@ Coverage Diff @@
## master #18 +/- ##
==========================================
- Coverage 98.29% 98.26% -0.03%
==========================================
Files 2 2
Lines 117 115 -2
==========================================
- Hits 115 113 -2
Misses 1 1
Partials 1 1
Continue to review full report at Codecov.
|
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.
Thanks for the PR!
if defaultVal != "" && defaultVal != "{}" { | ||
if err := json.Unmarshal([]byte(defaultVal), ref.Interface()); err != nil { | ||
if err := json.Unmarshal([]byte(defaultVal), field.Addr().Interface()); err != nil { |
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.
Neat 👍
defaults.go
Outdated
return err | ||
} | ||
callSetter(ref.Interface()) | ||
field.Set(ref.Elem()) | ||
callSetter(field.Addr().Interface()) |
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.
It seems to be a redundant call as you're already doing it in Set
.
Either one of them should be removed. Perhaps the latter.
Could you also change the title to be more descriptive? |
@creasty review again please |
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.
Looking good. Thanks!
fix #16 #17