mardi 26 juin 2018

Removing a pointer from reflect.Type

I have a reflect.Type that contains a double-pointer to a struct. I'd like to be able to remove one level of indirection to have a pointer to the struct. Is this possible? For example, I'd like to do this:

func foo(x interface{}) {
    typ := reflect.TypeOf(x)
    fmt.Printf("%v", typ) // prints **Foo
    realType := typ.PointsTo()
    fmt.Printf("%v", typ) // prints *Foo
}

But as far as I can see, this functionality does not exist. There is an Indirect function that operates on Values, but I can't see anything similar that works on Types.





Aucun commentaire:

Enregistrer un commentaire