vendredi 6 octobre 2017

Golang getting the result of a reflection call

I'm making a reflection function call but I'm currently stuck on trying to get the return values.

Example code:

func (c *Client) Send(funcName protoFunction, data interface{}) (interface{}, error) {
    funcList := c.GetProtoFuncList()
    ctx := context.Background()
    f := reflect.ValueOf(funcList[funcName.String()])
    vals := make([]reflect.Value, 2)
    vals[0] = reflect.ValueOf(ctx)
    vals[1] = reflect.ValueOf(data)
    value := f.Call(vals)
    log.Debug(value)
    return nil, nil
}

How do I get the return values from "value" and return them correctly?

Cheers





Aucun commentaire:

Enregistrer un commentaire