Golang Protoc编译器命令的相对路径问题

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

Golang Protoc Compiler Command relative_path problem

问题

我尝试在Golang中学习gRPC。我编写了一个调用service.proto的.proto文件,并尝试使用以下命令进行编译:

  1. protoc --go_out=. --go_opt=paths=source_relative \
  2. --go-grpc_out=. --go-grpc_opt=paths=source_relative \
  3. proto/service.proto

但是我不确定在source_relative的位置应该写什么。我尝试写入"protoc-gen-go.exe"和"protoc-gen-go.exe"的包路径,但是它抛出以下错误:

  1. protoc-gen-go: unknown path type "C:/Users/Onur/go/bin": want "import" or "source_relative"

这是我的.proto文件:

  1. syntax = "proto3";
  2. package proto;
  3. message Request {
  4. int64 a = 1;
  5. int64 b = 2;
  6. }
  7. message Response {
  8. int64 result = 1;
  9. }
  10. service AddService {
  11. rpc Add(Request) returns(Response);
  12. rpc Multiply(Request) returns(Response);
  13. }

请注意,我只提供了翻译的部分,不包括代码部分。

英文:

I try to learn gprc in golang. I write a .proto calling service.proto and try to compile it with this command:

  1. protoc --go_out=. --go_opt=paths=source_relative \
  2. --go-grpc_out=. --go-grpc_opt=paths=source_relative\
  3. proto/service.proto

But I am not sure what I write instead of source_relative. I tried to write "protoc-gen-go.exe" and "protoc-gen-go.exe" packages path but it throws this error:

  1. protoc-gen-go: unknown path type "C:/Users/Onur/go/bin": want "import" or "source_relative"

This is my .proto file:

  1. syntax = "proto3";
  2. package proto;
  3. message Request {
  4. int64 a = 1;
  5. int64 b = 2;
  6. }
  7. message Response {
  8. int64 result = 1;
  9. }
  10. service AddService {
  11. rpc Add(Request) returns(Response);
  12. rpc Multiply(Request) returns(Response);
  13. }

答案1

得分: 1

在这个地方有一个错误:

  1. --go-grpc_opt=paths=source_relative\

\符号之前必须有一个空格。

尝试这样修改(对我有效):

  1. protoc --go_out=. --go_opt=paths=source_relative \
  2. --go-grpc_out=. --go-grpc_opt=paths=source_relative \
  3. proto/service.proto
英文:

mistake in this place:

  1. --go-grpc_opt=paths=source_relative\

there are must be space before \ symbol

try this (works for me):

  1. protoc --go_out=. --go_opt=paths=source_relative \
  2. --go-grpc_out=. --go-grpc_opt=paths=source_relative \
  3. proto/service.proto

huangapple
  • 本文由 发表于 2021年12月15日 02:42:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/70354053.html
匿名

发表评论

匿名网友

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

确定