如何将外部(在供应商文件夹上) proto导入到我自己的proto?
我用这个:
syntax = "proto3";
package command;
option go_package = "api";
import "github.com/service/command.proto";
service CommandService {
rpc Push(Command) returns (PushResponse);
}
message PushResponse {
string id = 1;
}但我得到了一个错误,即文件没有找到:
> protoc -I api api/command.proto --go_out=plugins=grpc:api
github.com/service/command.proto: File not found.这也给出了同样的错误:
> protoc -I api -I vendor/github.com/service api/command.proto --go_out=plugins=grpc:api
github.com/service/command.proto: File not found.我也尝试过在vendor/文件上加上.proto前缀,但没有成功。
发布于 2018-04-12 10:41:25
您需要一个-I每个文件夹,从开始寻找导入。然后,import使用导入语句中指定的相对路径尝试它们;so:使用:
protoc -I api [other-options] some.proto如果some.proto有import "github.com/service/command.proto";,那么您需要一个文件系统布局,如下所示:
[current folder]
- some.proto
- [api]
- [github.com]
- [service]
- command.proto(其中[...]是一个文件夹)
请注意,如果省略-I,则假定当前目录为单个导入根目录,因此您可以拥有:
[current folder]
- some.proto
- [github.com]
- [service]
- command.proto只需使用protoc [other-options] some.proto
https://stackoverflow.com/questions/49793856
复制相似问题