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

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

Golang Protoc Compiler Command relative_path problem

问题

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

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

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

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

这是我的.proto文件:

syntax = "proto3";

package proto;

message Request {
    int64 a = 1;
    int64 b = 2;
}

message Response {
    int64 result = 1;
}

service AddService {
    rpc Add(Request) returns(Response);
    rpc Multiply(Request) returns(Response);
}

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

英文:

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

protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative\
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:

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

This is my .proto file:

syntax = "proto3";

package proto;

message Request {
    int64 a = 1;
    int64 b = 2;
}

message Response {
    int64 result = 1;
}

service AddService {
    rpc Add(Request) returns(Response);
    rpc Multiply(Request) returns(Response);
}

答案1

得分: 1

在这个地方有一个错误:

--go-grpc_opt=paths=source_relative\

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

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

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

mistake in this place:

--go-grpc_opt=paths=source_relative\

there are must be space before \ symbol

try this (works for me):

protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
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:

确定