Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between protoc-gen-go and protoc-gen-go-grpc

Tags:

grpc-go

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 messages
  • protoc-gen-go-grpc contains the code for gRPC Server and Client

But, 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:

  1. why is this working with only protoc --go_out=. (why does it also generates gRPC client/server code?)
  2. what is the advantage of using one method vs. the other?

Thanks, DC

like image 694
user8285681 Avatar asked Feb 04 '23 14:02

user8285681


1 Answers

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.

like image 183
user8285681 Avatar answered May 16 '23 07:05

user8285681