Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在我的proto文件中为动态json使用google.protobuf.Struct时出错_Go_Protocol Buffers - Fatal编程技术网

在我的proto文件中为动态json使用google.protobuf.Struct时出错

在我的proto文件中为动态json使用google.protobuf.Struct时出错,go,protocol-buffers,Go,Protocol Buffers,我在我的proto文件中使用以下消息作为示例 message Report { string name = 1; string desc = 2; google.protobuf.Struct criteria = 3; } 并生成go客户端、服务器代码。当传递下面的json时 { "name": "My Report", "desc": "My first report", "criteria": {"fields": {"sum": "100"}} } 作为端点的

我在我的proto文件中使用以下消息作为示例

message Report {
    string name = 1;
    string desc = 2;
    google.protobuf.Struct criteria = 3;
}
并生成go客户端、服务器代码。当传递下面的json时

{
"name": "My Report",
"desc": "My first report",
"criteria": {"fields": {"sum": "100"}}
}
作为端点的post请求主体,并使用

import  "github.com/golang/protobuf/jsonpb"

var u api.Report
if err := jsonpb.Unmarshal(r.Body, &u); err != nil {...
我不断地发现这个错误:

level=info msg="panic: reflect.Set: value of type map[string]*structpb.Value is not assignable to type map[string]*structpb.Value"
我也尝试过使用gogo/protobuf/jsonpb,但也没有成功,尽管我仍在我的proto文件中导入

import "google/protobuf/struct.proto";

不确定我遗漏了什么。

根据错误,听起来您的项目中可能有两个
structpb
包的副本。不确定这是否是问题所在,尽管我有gogo和golang两个包。这取决于您使用哪个jsonpb,它应该选择正确的结构。您有解决方案吗?