Reputation: 958
How to import external (on vendor folder) proto into my own proto?
I'm using this:
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;
}
But I get an error that the file was not found:
> protoc -I api api/command.proto --go_out=plugins=grpc:api
github.com/service/command.proto: File not found.
Also this gives the same error:
> protoc -I api -I vendor/github.com/service api/command.proto --go_out=plugins=grpc:api
github.com/service/command.proto: File not found.
I tried prefixing with vendor/
on .proto file as well with no success.
Upvotes: 1
Views: 2451
Reputation: 1062975
You need a -I
per folder from which to start looking for imports. import
then tries all of them using the relative paths specified in the import statement; so: to use:
protoc -I api [other-options] some.proto
where some.proto
has import "github.com/service/command.proto";
, then you would need a file-system layout like:
[current folder]
- some.proto
- [api]
- [github.com]
- [service]
- command.proto
(where [...]
is a folder)
Note that if you omit -I
, then the current directory is assumed as a single import root, so you could have:
[current folder]
- some.proto
- [github.com]
- [service]
- command.proto
and just use protoc [other-options] some.proto
Upvotes: 1