我按照此链接中的 gRPC 快速入门文档https://grpc.io/docs/languages/go/quickstart/ 重新生成 gRPC 代码时出现错误(未知标志:--go_opt),如下所示。尝试了所有选项但不起作用。它还给出(未知标志:--go-grpc_opt)错误。
命令-
$ protoc \
--go_out=Mgrpc/service_config/service_config.proto=/internal/proto/grpc_service_config:. \
--go-grpc_out=Mgrpc/service_config/service_config.proto=/internal/proto/grpc_service_config:. \
--go-grpc_opt=paths=source_relative \
helloworld/helloworld.proto
Error - Unknown flag: --go_opt
我也有同样的问题。我删除了已安装的 protobuf 编译器,并使用“安装预编译的二进制文件”选项重新安装了 protobuf 编译器 https://grpc.io/docs/protoc-installation/。
sudo apt-get remove protobuf-compiler
$PB_REL="https://github.com/protocolbuffers/protobuf/releases"
$ curl -LO $PB_REL/download/v3.12.1/protoc-3.12.1-linux-x86_64.zip
$sudo apt install unzip
$unzip protoc-3.12.1-linux-x86_64.zip -d HOME/.local
$export PATH="$PATH:$HOME/.local/bin"
我遇到了同样的错误,然后我尝试了这样的方法:
protoc --proto_path=helloworld --go_out=paths=source_relative:. -I. helloworld/*.proto
您缺少第四行:
--go_opt=paths=source_relative \
。