Exposing services
Now that we have created a Protocol Buffer service, compiled it to Go, and created an implementation of the server interface, we are ready to spin up a server program that clients can use to invoke the logic in our service implementation.
The mechanism for registering service implementations differs slightly for each target language. The gRPC documentation site’s tutorials provides examples for each of the officially supported languages.
For Go, in addition to the server interface, protoc
also generates a registration
method that servers use to expose service implementations. Each such method accepts a
*grpc.Server
and a service implementation. In a given server, only a single
implementation of a particular service is allowed. (Attempts to register more than one
implementation of the same service interface will result in a panic.)
So let’s pull together this information by writing a Go program that will expose our service implementation. We’ll create...