I am trying to use reflect to set a pointer to a struct to nil
passed in through an interface{}
in Go.
I have this example program but it always prints false as a is not set to nil
. What am I doing wrong?
package main
import "reflect"
type MyStruct struct {}
func main() {
a := &MyStruct{}
wipePassed(a)
println(a == nil)
}
func wipePassed(r interface{}){
v := reflect.ValueOf(&r)
p := v.Elem()
p.Set(reflect.Zero(p.Type()))
}