调用reflect.Value.Set零值错误

时间:2017-06-30 18:49:50

标签: go reflection

我无法使用Elem().Set()为指针赋值。我得到call of reflect.Value.Set on zero Value error。我检查了我正在经过的价值,发现它并非零。我之前曾在同一个功能上工作,然后工作正常。我在这里缺少什么吗?

outputInterfaceAlias := reflect.ValueOf(output)
fmt.Printf("kind: %+v\n", outputInterfaceAlias.Kind())
if outputInterfaceAlias.Kind() != reflect.Ptr {
    panic("Passed value in output interface must be of POINTER type")
}
val := reflect.ValueOf(asyncOutput)
fmt.Printf("value: %+v\n", val)
outputInterfaceAlias.Elem().Set(val)

我得到的输出是:

kind: ptr
value: map[value:[map[SUM:2.711528e+06 SUM(total):4909]]]
echo: http: panic serving [::1]:60153: reflect: call of reflect.Value.Set on zero Value

0 个答案:

没有答案