vendredi 14 juin 2019

How to get access to a custom type in a reflect.Call return?

I know its not idiomatic to write generic functions in Go, but I want to explore my options before I dive into the go generate.

The problem I have is that the Value.Call() returns a slice where the element I interested in is a pointer to a custom struct. Seems like I cant find a way to access this.

returns := listMethod.Call([]reflect.Value{reflect.ValueOf(filter)})
fmt.Println(returns)

output

[<vspk.EnterpriseProfilesList Value> <*bambou.Error Value>]

type definition:

type EnterpriseProfilesList []*EnterpriseProfile

I want to get access to the vspk.EnterpriseProfilesList, but I am struggling to make it.

If I try to retrieve the underlying value like this:

returns := listMethod.Call([]reflect.Value{reflect.ValueOf(filter)})
ret1 := returns[0].Interface()
fmt.Println(ret1)

I receive

[0xc0000fc7e0]





Aucun commentaire:

Enregistrer un commentaire