i wanted to omit the fields which are not part of my struct.
but i was getting below error while running the below code.
is there any thing i am miss here?
1 error(s) decoding:
* '' has invalid keys: test
type MyStruct struct {
Name string
Age int
}
map1 := map[string]interface{}{
"name": "test",
"age": 30,
"test": "test",
}
// Create a new struct to hold the data
var data MyStruct
// Use mapstructure to map the data from the map to the struct
config := &mapstructure.DecoderConfig{
ErrorUnused: true,
Result: &data,
}
decoder, err := mapstructure.NewDecoder(config)
if err != nil {
fmt.Println(err)
return
}
if err := decoder.Decode(map1); err != nil {
fmt.Println(err)
return
}
i wanted to omit the fields which are not part of my struct. but i was getting below error while running the below code. is there any thing i am miss here?