qiubyte opened a new issue, #3157: URL: https://github.com/apache/dubbo-go/issues/3157
### ✅ 验证清单 - [x] 🔍 我已经搜索过 [现有 Issues](https://github.com/apache/dubbo-go/issues),确信这不是重复问题 ### 🚀 Go 版本 1.24.0 ### 📦 Dubbo-go 版本 v3.3.1 ### 🖥️ 服务端配置 dubbo-go v3.3.1 ### 💻 客户端配置 terminal curl http ### 🌐 协议配置 triple ### 📋 注册中心配置 nacos v3 ### 💾 操作系统 🍎 macOS ### 📝 Bug 描述 问题现象:dubbo-go 使用triple协议暴露服务,希望通过http方式调用传递参数并获取返回值。 错误信息:http body中json数据多传递了参数,或者说有些字段以前存在,现在从proto中被移除了,但是调用端还可能在使用,就会出现invalid_argument的错误。 ### 🔄 重现步骤 步骤 1. 定义接收参数 `type GsImportReq struct { state protoimpl.MessageState `protogen:"open.v1"` DeviceId *string `protobuf:"bytes,1,opt,name=deviceId,proto3,oneof" json:"deviceId,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache }` 2. curl 发起http调用 ` 正确: curl -H "Content-Type:application/json" -H "tri-service-group:uac" -H "tri-service-version:1.0.0" -X POST --data '{"deviceId":"tas"}' "http://127.0.0.1:50001/com.cc.uac.facade.UacGsInternalFacade/GsImport" 多加了参数就报错: curl -H "Content-Type:application/json" -H "tri-service-group:uac" -H "tri-service-version:1.0.0" -X POST --data '{"deviceId":"tas","plat":"saas"}' "http://127.0.0.1:50001/com.cc.uac.facade.UacGsInternalFacade/GsImport" ` ### ✅ 预期行为 期望能收到正确的业务返回值 ### ❌ 实际行为 实际provider端返回错误信息。{"code":"invalid_argument","message":"unmarshal into *GsImportReq: proto: (line 1:24): unknown field \"plat\""} ### 💡 可能的解决方案 跟踪代码发现 triple_protocol/codec.go 中使用到 protojson.UnmarshalOptions DiscardUnknown 默认为false,会严格比对参数。 ` func (c *protoJSONCodec) Unmarshal(binary []byte, message any) error { protoMessage, ok := message.(proto.Message) if !ok { return errNotProto(message) } if len(binary) == 0 { return errors.New("zero-length payload is not a valid JSON object") } var options protojson.UnmarshalOptions return options.Unmarshal(binary, protoMessage) } ` var options protojson.UnmarshalOptions 是否可以添加DiscardUnknown: true,或者通过配置方式让使用者自己决定要不要严格限制 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
