警告:缺少 ‘go_package’ 选项

huangapple go评论75阅读模式
英文:

WARNING: Missing 'go_package' option

问题

当我运行协议命令生成pb.go文件时,我遇到了以下错误。但是我可以生成pb.go文件。我该如何解决以下错误?

在"job.proto"中缺少"go_package"选项,
请使用完整的Go包路径指定它,
因为protoc-gen-go的未来版本将要求指定此选项。
英文:

Im getting the following error once i run the protocol command to generate pb.go file
But I can generate the pb.go file. how do I mitigate the following error

Missing 'go_package' option in "job.proto",
please specify it with the full Go package path as
a future release of protoc-gen-go will require this be specified.

答案1

得分: 4

"Import path"是另一个包用来导入生成的代码的路径,例如github.com/me/myproject/model,或者您可以根据您的偏好简单地定义导入路径。

您可以按照以下方式简单地定义您的可选导入路径:

option go_package = ".;<您的导入路径>";

例如,我们可以将包路径假设为"/pub",那么语句如下所示:

option go_package = ".;pub";

然后,您可以简单地执行protoc命令来生成pb.go文件:

protoc -I=<绝对路径输出目录> --go_out=<绝对路径proto文件>
英文:

"Import path" is the path another package would use to import the generated code, e.g. github.com/me/myproject/model or You can simply define the import path based on your preference.

You can simply define your optional import path as follows

option go_package = &quot;.;&lt;Your_Import_path&gt;&quot;;

For example, we can assume the package path as "/pub", So the statement as follows.

option go_package = &quot;.;pub&quot;;

Then you can simply execute the protoc command to generate the pb.go file

protoc -I=&lt;ABS_PATH_OUTPUT_DIR&gt; --go_out=&lt;ABS_PATH_PROTO_FILE&gt;

huangapple
  • 本文由 发表于 2021年5月25日 03:12:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/67677709.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定