2

I have two proto src file, in same folder, let's say:

the 1st one is foo.proto

syntax = "proto3";
package foo;

the second is bar.proto, which need import foo.proto

syntax = "proto3";
import "foo.proto";
package bar;

you can see they have different package name, when I use protoc to generate them one by one, (foo.proto as the 1st of cause), I have two golang file generated, but I have to put them into 2 directory (you can't put different package name file inside same directory, golang )

foo/foo.pb.go
bar/bar.pb.go

but inside bar.pb.go the import are using local import path, which is like

import foo "."

I'm tweeking several options which protoc provided, but didn't make this work, any suggestion?

har07
  • 88,338
  • 12
  • 84
  • 137
rmrf100
  • 71
  • 1
  • 10
  • Are your .proto files next to each other? Have you tried arranging the folders such that the paths to protoc look like the paths you want to get out? So: proto bar/bar.proto with import "foo/foo.proto"? – Marc Gravell Jun 22 '17 at 06:59
  • it is normally easiest to have all proto files in their own folder `protos/foo.proto`, `protos/bar.proto` and then compile. The output `.pb.go`'s can then be moved to the package you want them in. – RickyA Jun 22 '17 at 09:29
  • all these proto files located in same folder (with different package), sadly I can't change that - other teams' code, they are using JAVA with pom.xml setup, seems it does not have these kind of issue. – rmrf100 Jun 22 '17 at 10:24
  • if I can add `option go_package` into the proto file, that will fix this, but sadly I can't modify the original proto file. and seems `import_prefix` is not working as I expected in this case. – rmrf100 Jun 22 '17 at 10:43

1 Answers1

1

I believe add option go_package should be the correct solution

rmrf100
  • 71
  • 1
  • 10