英文:
Can't generate grpc files for go
问题
有一个目录结构如下:
├── cmd
│ └── main.go
├── go.mod
└── proto
└── forward.proto
在终端中输入以下命令:
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
proto/forward.proto
我得到了以下错误信息:
> protoc-gen-go: invalid Go import path "forward" for
> "proto/forward.proto"
>
> 导入路径必须至少包含一个正斜杠('/')字符。
>
> 有关更多信息,请参阅
> https://developers.google.com/protocol-buffers/docs/reference/go-generated#package。
>
> --go_out: protoc-gen-go: Plugin failed with status code 1. a.mamedov@a-mamedov forward-spinner %
如何修复这个问题并为 forward.proto 文件生成 grpc 代码?
英文:
There is a directory
├── cmd
│ └── main.go
├── go.mod
└── proto
└── forward.proto
write in the terminal
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
proto/forward.proto
I get the error
> protoc-gen-go: invalid Go import path "forward" for
> "proto/forward.proto"
>
> The import path must contain at least one forward slash ('/')
> character.
>
> See
> https://developers.google.com/protocol-buffers/docs/reference/go-generated#package
> for more information.
>
> --go_out: protoc-gen-go: Plugin failed with status code 1. a.mamedov@a-mamedov forward-spinner %
How to fix it and generate grpc for forward.proto file?
答案1
得分: 9
问题出在.proto
文件中的option go_package="forward";
这一行。
为了编译代码,只需在所需文件前面添加./
:
option go_package="./forward";
英文:
The problem lies on the .proto
file, in line option go_package="forward";
.
In order to compile the code just add ./
in front of the require file:
option go_package="./forward";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论