We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
In this kind of structure:
type A struct { StrPtr *string `default:""` }
A.StrPtr is not set to a pointer of String("") but is still nil.
A.StrPtr
String("")
nil
package main import ( "fmt" "github.com/creasty/defaults" ) type A struct { StrPtr *string `default:""` } func main() { var data A err := defaults.Set(&data) if err != nil { panic(err) } fmt.Println(data.StrPtr) }
My guess is it's related to https://github.com/creasty/defaults/blob/master/defaults.go#L238 that does not change the field if the tag is empty, or an empty tag could be an empty string here.
I'm wondering if just returning true at the end of the shouldInitializeField method can work or it may break other cases?
true
shouldInitializeField
The text was updated successfully, but these errors were encountered:
We'd like to utilize Lookup() here to exclude fields without a tag, and then change shouldInitializeField to return true at the end.
defaults/defaults.go
Line 36 in abebf4b
Sorry, something went wrong.
No branches or pull requests
In this kind of structure:
A.StrPtr
is not set to a pointer ofString("")
but is stillnil
.Example of program highlighting this bug
My guess is it's related to https://github.com/creasty/defaults/blob/master/defaults.go#L238 that does not change the field if the tag is empty, or an empty tag could be an empty string here.
I'm wondering if just returning
true
at the end of theshouldInitializeField
method can work or it may break other cases?The text was updated successfully, but these errors were encountered: