I wrote some proto files that one import others.
like this:
package myproto;
import "a.proto";
import "b.proto";
import "c.proto";
import "d.proto";
import "e.proto";
these files are all in package myproto;
When I generated pb.go files and import "myproto"
go compiler told:
import cycle not allowed
package .
imports myproto
imports .
imports .
echo.go:5:2: local import "." in non-local package
Is it a bug of protoc-gen-go?
If foo.proto imports bar.proto, they need to generate code in different Go packages, or else be run through protoc together. What commands did you run to get the generated .pb.go files?
protoc --go_out=. a.proto
protoc --go_out=. b.proto
protoc --go_out=. c.proto
protoc --go_out=. d.proto
protoc --go_out=. e.proto
I did similar script when i generated cpp files?
How to "be run through protoc together"
thanks for your reply
You haven't told protoc-gen-go how to map a.proto to a Go import path, which is why it ended up with a dot. Try protoc --go_out=. a.proto b.proto c.proto d.proto e.proto, or put them in different directories, or use the M parameter (carried in the --go_out flag) to specify what it should do.
I did what you told me to do and It works now, thank you very much
@dsymonds How to use the M parameter? I have two proto files: a.proto with package a and b.proto with package b, a.proto imports b. proto. When compiled with protoc --go_out=. a.proto b.proto, protoc failed with inconsistent package names: a b. Thanks!
If you've got two proto files that are going into the same package (implied by passing them on the command line together), they need to have the same package name.
Also see #39.
Most helpful comment
You haven't told protoc-gen-go how to map
a.prototo a Go import path, which is why it ended up with a dot. Tryprotoc --go_out=. a.proto b.proto c.proto d.proto e.proto, or put them in different directories, or use theMparameter (carried in the--go_outflag) to specify what it should do.