I am creating a struct instance at runtime. The instance has been created successfully, but I can't unmarshal JSON into it.
type Test struct {
Name string `json:"name,omitempty"`
}
func create(a interface{}) {
aType := reflect.TypeOf(a).Elem()
elType := aType.Elem()
f := reflect.Indirect(reflect.New(elType))
b := []byte(`{"name": "go"}`)
err := json.Unmarshal(b, &f)
fmt.Println(err, f)
}
func main() {
l := []Test{}
create(&l)
}