Protobuf: Using Go modules with vendor-provided Protobuf .proto imports?

Created on 10 Jul 2019  Â·  4Comments  Â·  Source: golang/protobuf

In my proto file:

syntax = "proto3";

package pb;

import "github.com/abc/abc/api.proto";

Without Go modules, we could do this:

protoc -I. I$GOPATH/src --go_out=. proto/*.proto

But Go modules github.com/abc/abc is versioned, for example github.com/abc/[email protected] , so the above command failed, because path not exists。

Here, my questions is how do I import vendor-provided protobuf(without copy to the GOPATH)?

Thanks a lot!

Most helpful comment

go list can probably solve your issue

$ go list -m -f "{{.Dir}}" github.com/abc/abc
github.com/abc/[email protected]

This might do

protoc -I. I`go list -m -f "{{.Dir}}" github.com/abc/abc` --go_out=. proto/*.proto

All 4 comments

go list can probably solve your issue

$ go list -m -f "{{.Dir}}" github.com/abc/abc
github.com/abc/[email protected]

This might do

protoc -I. I`go list -m -f "{{.Dir}}" github.com/abc/abc` --go_out=. proto/*.proto

@millergarym thanks a lot.
But in this case, my proto file should change to this:

syntax = "proto3";

package pb;

import "api.proto";          // this will be confuse whether api.proto from the project or the vendor!

not my original one:

syntax = "proto3";

package pb;

import "github.com/abc/abc/api.proto";

Making this a duplicate of #748.

thanks @dsnet !

748 seems not relate to this. and tried mod_root, not work!

Was this page helpful?
0 / 5 - 0 ratings