如何将外部(在 vendor 文件夹中)原型(prototype)导入我自己的原型(prototype)?
我正在使用这个:
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.
我也尝试在 .proto 文件上加上 vendor/
前缀,但没有成功。
最佳答案
每个 文件夹 都需要一个 -I
,开始 查找导入。 import
然后使用 import 语句中指定的相对路径尝试所有这些;所以:使用:
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
关于go - 在自己的原型(prototype)上导入 vendor 原型(prototype),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49793856/