【问题标题】:grpc doesnt compile my messages correctlygrpc 没有正确编译我的消息
【发布时间】:2021-03-25 22:57:59
【问题描述】:

我正在尝试编译我的 .proto 文件:

syntax = "proto3";

package chat;

message Person {
  string name = 1;
  string family = 2;
  int32 age = 3;
}

message SearchPerson {
  string name = 1;
}

service PersonService {
  rpc GetPerson (SearchPerson) returns (Person) {}
  rpc GetPeople (SearchPerson) returns (stream Person) {}
}

当我运行这个命令时:

./bin/protoc --go-grpc_out=. ./proto/person.proto

为我创建的新文件 (person_grpc.pb.go) 但我的消息和服务出现错误:

UnResolved Type for SearchPerson

您可以看到新文件为我的消息和服务提供了错误(未解析类型)。 有什么问题?

【问题讨论】:

  • 你能把你在proto文件中的包重命名为grpc以外的名字吗?这可能与 grpc 包导入冲突。
  • 我把包改成通讯,又试了一遍,没有任何变化

标签: go protocol-buffers grpc protoc


【解决方案1】:

我建议您在文件 (as described in the doc) 中添加 go_package 指令,以理想地反映您的包/项目路径,例如:

syntax = "proto3";

package chat;

option go_package = "example.com/foo/chat";

// option go_package = "chat";


message Person {
  string name = 1;
  string family = 2;
  int32 age = 3;
}

然后相应地更改您的脚本

./bin/protoc --go-grpc_out=./chat ./proto/person.proto

那么你应该可以从项目的chat 包中使用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    • 2017-12-12
    • 1970-01-01
    • 2016-11-20
    • 2018-10-12
    • 1970-01-01
    • 2016-02-28
    相关资源
    最近更新 更多