在自己的原型上导入供应商原型



如何将外部(在供应商文件夹上(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.

我也尝试在 .proto 文件上加上 vendor/ 前缀,但没有成功。

您需要

每个文件夹-I才能开始查找导入。 然后,import使用 import 语句中指定的相对路径尝试所有这些路径;所以:使用:

protoc -I api [other-options] some.proto

如果some.protoimport "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

最新更新