在我的proto文件中为动态json使用google.protobuf.Struct时出错
我在我的proto文件中使用以下消息作为示例在我的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"}} } 作为端点的
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,它应该选择正确的结构。您有解决方案吗?