I'm a bit confused about protoc-gen-go
vs protoc-gen-go-grpc
. I know that:
protoc-gen-go
contains that code for the serialization/deserialization of protobuf messagesprotoc-gen-go-grpc
contains the code for gRPC Server and ClientBut, I'm using the following command
protoc -I $protodir --go_out=plugins=grpc:./genproto/ $protodir/v1/foo.proto
and the generated foo.pb.go
contains both code for message serialization and for gRPC server/client. Plus that I only have protoc-gen-go
installed on my system.
I have the feeling that this is the old-way of doing gRPC in GO while the new-way is with protoc --go_out=. --go-grpc_out=.
Questions:
protoc --go_out=.
(why does it also generates gRPC client/server code?)Thanks, DC
The old-way is using the github.com/golang/protobuf
module. It comes with protoc-gen-go
that generates both serialization of the protobuf messages and grpc code (when --go_out=plugins=grpc
is used).
The so-called new-way is using the google.golang.org/protobuf
module = a major revision of the Go bindings for protocol buffers. It comes with a different protoc-gen-go
that no longer supports generating gRPC service definitions. For gRPC code, a new plugin called protoc-gen-go-grpc
was developed by Go gRPC project.
The plugins
flag, which provided a way to invoke the gRPC code generator in the old-way, is deprecated.
Important note: Users should strive to use the same version for both the runtime library and the protoc-gen-go plugin used to generate the Go bindings.
The longer answer on stackoverflow.
Also the Release Notes explains this.