You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func main() {
type requestBody struct {
Title *string
Description *string
ProductType *string
Brand *string
}
content := []byte(`{"description": "Hello-World"}`)
var result requestBody
err := json.Unmarshal(content, &result)
if err != nil {
log.Fatal(err)
}
fields := structs.Map(result)
updateFields := make(map[string]interface{})
for name, value := range fields {
if value != nil {
// no nil values should be printed here
// Because we already checked nil values in line 31.
// But why it's printing the value?
//
//
// ORIGINAL OUTPUT:
// Title - (*string)(nil)
// Description - (*string)(0xc00010a140)
// ProductType - (*string)(nil)
// Brand - (*string)(nil)
//
// OUTPUT I WANT:
// Description - (*string)(0xc00010a140)
//
fmt.Printf("%v - %#v\n", name, value)
updateFields[name] = reflect.Indirect(reflect.ValueOf(value))
}
}
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes!
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/rcCFGJNhHYh
My code
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: