无法为Go生成gRPC文件。

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

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";

huangapple
  • 本文由 发表于 2021年8月3日 22:03:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/68637511.html
匿名

发表评论

匿名网友

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

确定