Reputation: 1801
I have two services that talk to each other and have separate protofiles. There are a couple of messages type common between the two. When an attempt to test run I get:
2020/08/24 13:40:42 WARNING: proto: file "delivery.proto" has a name
conflict over release.Patient previously from:
"gitlab.com/dhf0820/roirelease/protobufs/relPB" currently from:
"gitlab.com/dhf0820/roi_delivery/protobufs/delPB"
As you can see they have different package names relPB and delPB. The patient is used in both services and I marshal/unmarshal between the two to send the proper message. I am not sure if this is the correct way.
Is there a better way or what is going on. I seem to be having unique names.
Upvotes: 3
Views: 9117
Reputation: 141
The official Go Protocol Buffers FAQ has an answer for "What is a protocol buffer namespace conflict?" and for "How do I fix a protocol buffer namespace conflict?" that helps explain this. The short summary is you need to have only a single Go version in your program, or you need to pass special linker flags or environment variables to your programs.
Upvotes: 0
Reputation: 1400
It looks like the names are unique in the generated Go code domain, but not in the protobuf domain.
You can really view protobuf as its own language, with its own package and namespace semantics (in practice, similar to C++). In that domain, the actual file names don't matter, only the package defined in the file.
Both your files probably have package release;
at the top. This means that, in the protobuf world, release.Patient
is defined twice. protoc
may still be able to generate working Go code by accident, but it's still a malformed proto definition. You may not have the same luck if you try to use the same definition in other languages (e.g. C++) or if you try to use libraries that depend on proto reflection. It may also break if you try to use one of the messages as a field in another file; which release.Patient
will that refer to?
Upvotes: 4