How it works...
Although this recipe omits the client, you could replicate the steps in the Understanding GRPC clients recipe from Chapter 6, Web Clients and APIs, and you should see identical results to what we see with our curls. Both the http and grpc directories make use of the same internal package. We have to be careful in this package to return appropriate GRPC error codes and to correctly map those error codes to our HTTP response. In this case, we use codes.NotFound, which we map to http.StatusNotFound. If you have to handle more than a few errors, a switch statement may make more sense than an if…else statements.
The other thing you may notice is that GRPC signatures are usually very consistent. They take a request and return an ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access