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!
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 !
Most helpful comment
go listcan probably solve your issueThis might do