0

我正在尝试从官方文档中学习 GRPC,这是我遵循grpc-go的教程

使用此命令生成原型

protoc  --go_out=$PWD  helloworld/helloworld.proto

上述命令将helloworld.pb.go毫无问题地生成文件,但问题是生成的文件中缺少客户端存根的代码

syntax = "proto3";
package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}

我从客户端连接得到的实际错误是

未定义:helloworld.NewGreeterClient

这是从文件中的行发生c := pb.NewGreeterClient(conn)greeter_client/main.go

背后的原因是因为在生成的文件中没有生成客户端存根

4

2 回答 2

0

问题已解决 我的命令有一些问题

这是实际的命令

protoc   --go_out=plugins=grpc:$PWD helloworld.proto
于 2020-02-03T13:00:15.683 回答
0

将 --I 添加到您的命令中。例如

protoc -I helloworld --go_out=${PWD} helloworld/*.proto
于 2020-02-03T13:00:25.640 回答