GRPC-GO:生成的 pb.go 文件中未显示客户端存根

GRPC-GO:Client stub not shown in the generated pb.go file

我正在尝试从官方文档学习 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;
}

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

undefined: helloworld.NewGreeterClient

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

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

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

这是实际的命令

protoc   --go_out=plugins=grpc:$PWD helloworld.proto

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

protoc -I helloworld --go_out=${PWD} helloworld/*.proto