我正在构建一个 gRPC 函数(称为 myFunc),该函数将以下 JSON 数据的等效项作为其参数:
{
"id": "ABCD4435010",
"otherId": "WXYZ4435010",
"duration": 30
}
作为本练习的一部分,我需要设计原型布夫消息。它看起来像这样:
1: // MyFunc does something I guess.
2: rpc MyFunc(MyFuncRequest) returns (MyFuncResponse) {
3: option (google.api.http) = {
4: post: "/my.path.to.endpoint/MyFunc"
5: body: "*"
6: };
7: }
8:
9: // MyFuncRequest is the request object for MyFunc.
10: message MyFuncRequest {
11: // id is something.
12: string id = 1;
13: // otherId is something.
14: string otherId = 2;
15: // duration is something.
16: string duration = 3;
17: }
当我尝试从中生成 golang 文件时,我收到以下错误:
myFile.proto:14:3:Field name "otherId" must be lower_snake_case.
myFile.proto:16:3:Field "duration" must be a google.protobuf.Duration.
这些错误的 2 个问题:
如果我更改为它将不再与 JSON 中的键名匹配。otherIdother_id
如果我将字段的类型更改为它将不再与JSON中的数据类型匹配。因此,编组/取消编组将失败。durationgoogle.protobuf.Duration
如何解决这些错误消息并让我的协议缓冲区编译?
呼啦一阵风
千巷猫影
拉丁的传说
相关分类