Query on the using protobuf module
Hi,
In the documentation it is mentioned that usage of "github.com/golang/protobuf" is deprecated and instead use "google.golang.org/protobuf". But when I checked the go.mod file of the latest tag of "google.golang.org/protobuf" it still refers to "github.com/golang/protobuf" v1.5.0.
https://github.com/protocolbuffers/protobuf-go/blob/v1.34.2/go.mod has reference to "github.com/golang/protobuf".
Does this mean both the modules can still be used ?
Second question is, if we try to use the "google.golang.org/protobuf" in our application code by removing the references to "github.com/golang/protobuf" in go.mod file, on compiling the code, he go.mod file still contains references to github.com/golang/protobuf. May be the dependency got added by some other module or the interfaces in the code needs to be changed. But my question is still, can both the modules still co-exist ?
Regards, Wahid
New code should use google.golang.org/protobuf.
github.com/golang/protobuf is deprecated. Versions v1.4.0 and newer of that module are mostly a wrapper around the newer google.golang.org/protobuf module. Existing programs that use github.com/golang/protobuf may continue to do so, and will continue to work for the foreseeable future.
A program may use both github.com/golang/protobuf and google.golang.org/protobuf, so long as it uses a new enough version of the old module. This is why google.golang.org/protobuf's go.mod includes a dependency on v1.5.0 of github.com/golang/protobuf--if a program uses both modules, this ensures that it will use a set of versions that can coexist.
Second question is, if we try to use the "google.golang.org/protobuf" in our application code by removing the references to "github.com/golang/protobuf" in go.mod file, on compiling the code, he go.mod file still contains references to github.com/golang/protobuf.
This probably indicates that you've got a file which is importing github.com/golang/protobuf somewhere in your program (either in your own code, or in one of your dependencies). This is fine, the two modules will cooperate.
Second question is, if we try to use the "google.golang.org/protobuf" in our application code by removing the references to "github.com/golang/protobuf" in go.mod file, on compiling the code, he go.mod file still contains references to github.com/golang/protobuf.
This probably indicates that you've got a file which is importing
github.com/golang/protobufsomewhere in your program (either in your own code, or in one of your dependencies). This is fine, the two modules will cooperate.
Yeah, I think this is because they import github.com/golang/protobuf at a version >= 1.4.0, so it drags in the new package (like we expect it to). I mean, there’s just literally no way to import the old package at and after version 1.4.0 that doesn’t indirectly pull in the new package, and that’s by design.
Thank You all for explaining the logic behind this inter dependencies. I learnt its actually safe to use "google.golang.org/protobuf" without bothering the references to the other package path, it seems to have internally handled.