I have 2 proto compiled under different go packages but when I register them in a a server and run it, I get :
panic: proto: file "common.proto" is already registered
previously from: "github.com/soft/test-platform.go/common"
currently from: "github.com/soft/proto-asterix/asterix"
Here is common.proto in test-platform repository (in /api
folder) :
syntax = "proto3";
package soft.testplatform.common; // here I do defint a UNIQUE package name !
option java_multiple_files = true;
option go_package = "github.com/soft/test-platform.go/common"; // Here I do define a unique go package name !
message MyMessage{
string commandId = 1;
}
As you can see, the package definition for go_package and package do not collide with package from github.com/soft/proto-asterix/asterix. Only the .proto filenames are similar (common.proto).
I generate go files with protoc an protoc-gen-go plugin using the following command :
protoc \
--proto_path=../test-platform/api/ \
--go_out=./common --go_opt=paths=source_relative \
../test-platform/api/common.proto
As per documentation here https://developers.google.com/protocol-buffers/docs/reference/go/faq#fix-namespace-conflict the package and filename should be appended to check for a registration conflict but it does not seem to be the case here.
Has anyone encountered such behavior ? Do I miss something obvious to resolve this package name collision ?
Here is what I tried :
package
instruction to common.proto
fileproto_path
Protoc version : libprotoc 3.15.7 Protoc go plugin version : protoc-gen-go v1.26.0
Current implementation doesn't support a proto file that has multiple services in it(Basically this should enable running multiple services on same port).
In the service project, you need to add a proto file, then add the Protobuf element to the ItemGroup. Then you need to build the project. After that, in the client's project, you need to add the Protobuf element to the ItemGroup and build the project.
A . proto file is similar to a JSON file in that it represents structured data, but you can run a compiler on the . proto file to generate code that can read and write the data in the programming language of your choice. For more information about protocol buffers, see Protocol Buffer Developer Guide on Google's site.
Thanks to @blackgreen suggestion, indeed, this was a bug fixed by https://go-review.googlesource.com/c/protobuf/+/301953/
While the next release of protoc-gen-go is out, here is a quick fix for your projects :
go install google.golang.org/protobuf/cmd/protoc-gen-go@febffdd
go.mod
to matchgoogle.golang.org/protobuf v1.26.1-0.20210525005349-febffdd88e85
You should be good to go !
The accepted answer is not correct anymore. This commit reverted the "bugfix" as it was different from other gRPC implementations.
My only way to fix this was to rename the file/folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With