xpt*_*xpt 8 go protocol-buffers protoc grpc-go
与 protoc-gen-go 相同的症状:无法确定“simple.proto”的 Go 导入路径
\n\n\n对于具有以下内容的简单原型文件。
\nRun Code Online (Sandbox Code Playgroud)\nsyntax="proto3";\n\npackage main;\n\nmessage Person {\n string name = 1;\n int32 age = 2; \n}\n我正在尝试使用 protoc 为其生成 go 代码。我跑:
\nRun Code Online (Sandbox Code Playgroud)\nprotoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative simple.proto\n我收到以下错误:
\nRun Code Online (Sandbox Code Playgroud)\nprotoc-gen-go: unable to determine Go import path for "simple.proto"\n\nPlease specify either:\n \xe2\x80\xa2 a "go_package" option in the .proto source file, or\n \xe2\x80\xa2 a "M" argument on the command line.\n
那里的所有答案都集中在第一个选项 - 添加a "go_package" option in the .proto source file,但我正在寻找第二个选项“命令行上的“M”参数”的答案。
与/sf/answers/4377844201/下的评论相同
\n我正在寻找通过protoc更改模块路径的方法,为属于不同模块的客户端和服务器生成 Go 代码,我尝试使用go_opt=module,但它不适用于source_relative.
有什么方法可以通过在命令行上添加“a“M”参数”来使其工作,而不是go_package在 .proto 源文件中添加“”选项?
具体来说,对于\n https://github.com/mmcc007/go/blob/master/examples/helloworld/helloworld/helloworld.proto的文件
\n以下是我失败的尝试:
\n$ protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative --proto_path=examples/helloworld/helloworld helloworld.proto\xc2\xa0\n\nprotoc-gen-go: unable to determine Go import path for "helloworld.proto"\n. . .\n--go_out: protoc-gen-go: Plugin failed with status code 1.\n\n\n$ protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative --proto_path=examples/helloworld/helloworld --go_opt=Mhelloworld.proto=github.com/mmcc007/go/blob/master/examples/helloworld/helloworld helloworld.proto\xc2\xa0\n\nprotoc-gen-go-grpc: unable to determine Go import path for "helloworld.proto"\n. . .\n--go_out: protoc-gen-go: Plugin failed with status code 1.\n\nRun Code Online (Sandbox Code Playgroud)\n
我发现这可以--proto_path使用“THE M FLAG”轻松参考:-)
protoc --proto_path=./proto \
--go_out=./go \
--go_opt=Mhelloworld.proto=example.com/project/protos/fizz \
./proto/helloworld.proto
Run Code Online (Sandbox Code Playgroud)
注意:helloworld.proto 之前的 M
| 归档时间: |
|
| 查看次数: |
6277 次 |
| 最近记录: |