英文:
getting Unimplemented name Error in generated go file from proto
问题
每次我生成代码时,都会出现这个错误:
这是我的.proto文件:
我用来生成代码的命令是:
protoc pb/pb.proto --go-grpc_out=./pb
英文:
Every time, I generate the code, I am getting this error:
this is my .proto file:
the command that, I use to generate the code is::
protoc pb/pb.proto --go-grpc_out=./pb
答案1
得分: 1
请尝试使用以下命令生成代码:
protoc -I <proto文件夹路径> --go_out=plugins=grpc:<存储生成的go文件的文件夹路径> <proto文件夹路径>/*.proto
在你的情况下,可以使用以下命令:
protoc -I pb/ --go_out=plugins=grpc:pb/ pb/*.proto
英文:
Please try this command to generate the code
protoc -I <proto-file-folder/> --go_out=plugins=grpc:<folder-to-store-generated-go-file> <proto-file-folder>/*.proto
In your case
protoc -I pb/ --go_out=plugins=grpc:pb/ pb/*.proto
答案2
得分: -1
根据教程,你需要向protoc
传递两个参数:--go_out
和--go-grpc_out
(你可能还想传递相关的_opt
参数):
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
routeguide/route_guide.proto
在你的情况下,翻译为:
protoc pb/pb.proto --go_out=./pb --go-grpc_out=./pb
你看到错误的原因是--go-grpc_out
告诉protoc
运行protoc-gen-go-grpc
(来自google.golang.org/grpc/cmd/protoc-gen-go-grpc
)。这个可执行文件只生成gRPC特定的代码;它假设已经创建了在protoBuf和Go结构之间进行转换所需的代码(这是由protoc-gen-go
触发的,通过--go_out
参数)。
英文:
As per the tutorial you need to use pass protoc
two parameters; --go_out
and --go-grpc_out
(you probably also want to pass the associated _opt
parameters):
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
routeguide/route_guide.proto
In your case this translates to:
protoc pb/pb.proto --go_out=./pb --go-grpc_out=./pb
The reason for the error that you were seeing is that --go-grpc_out
tells protoc
to run protoc-gen-go-grpc
(from google.golang.org/grpc/cmd/protoc-gen-go-grpc
). This executable only generates the gRPC specific code; it assumes that the code required to translate between protoBuf and Go structures has already been created (and this is done by protoc-gen-go
which is triggered by the --go_out
).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论