Defining gRPC service

Next we need to generate the gRPC client and server interfaces from our .proto service definition. We do this using the protocol buffer compiler protoc with a special gRPC Go plugin.

For simplicity, we’ve provided a bash script that runs protoc for you with the appropriate plugin, input, and output (if you want to run this by yourself, make sure you’ve installed protoc and followed the gRPC-Go installation instructions first):

codegen.sh route_guide.proto

which actually runs:

protoc --go_out=plugins=grpc:. route_guide.proto

Running this command generates the following file in your current directory:

  • route_guide.pb.go

This contains:

  • All the protocol buffer code to populate, serialize, and retrieve our request and response message types
  • An interface type (or stub) for clients to call with the methods defined in the RouteGuide service.
  • An interface type for servers to implement, also with the methods defined in the RouteGuide service.

https://github.com/grpc/grpc-go/blob/master/examples/gotutorial.md


See also