【问题标题】:Unknown flag: --go_opt while regenerating gRPC code未知标志:--go_opt 在重新生成 gRPC 代码时
【发布时间】:2020-07-15 06:46:12
【问题描述】:

我按照此链接https://grpc.io/docs/languages/go/quickstart/ 中的 gRPC 快速入门文档进行操作,在重新生成 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

【问题讨论】:

  • 不是截图,你可以复制粘贴你运行的命令吗?看起来你遇到了这个问题:github.com/grpc/grpc.io/issues/298#issuecomment-656767393 你需要在你的 PATH 中安装 protoc-gen-go-grpc
  • 我已经尝试过 github.com/grpc/grpc.io/issues/298#issuecomment-656767393,因为它在grpc.io/docs/languages/go/quickstart 的提到的链接中给出。这是命令( cd ../../cmd/protoc-gen-go-grpc && go install .)
  • 您能否验证您的 PATH 中是否存在 protoc-gen-goprotoc-gen-go-grpc 二进制文件?
  • grpc-go/cmd下可以看到protoc-gen-go-grpc文件夹

标签: go grpc


【解决方案1】:

我也有同样的问题。我删除了已安装的 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"

【讨论】:

  • _opt 风格仅在较新版本的编译器上受支持。如果您不想安装比包管理器提供的更新版本,您也可以简单地将paths=source_relative 移动到--go_out= 部分,如--go_out=paths=source_relative:Mpath/to/file.proto=desired/go/package:<outdir>
【解决方案2】:

您缺少第 4 行:--go_opt=paths=source_relative \

【讨论】:

  • 是的,但这不是问题。您应该将此作为评论添加到最初的问题中。
  • @dcow 这就是问题所在。添加缺少的行,编译通过。
猜你喜欢
  • 1970-01-01
  • 2021-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-13
  • 1970-01-01
  • 2018-11-14
  • 2021-11-24
相关资源
最近更新 更多