Creating and Implementing Services
In the previous chapter, we learned a lot about Protocol Buffers. In particular,
we saw what the interface definition language looks like, how to define messages
and services, and how to use the protoc
tool to generate code in our desired
target language.
To create a service, we use what we learned in that chapter to write a .proto
source file that defines the service and the request and response types it needs.
Let’s start small: here is a service with just two methods for retrieving information
about movies from a database stored on the server. We’ll create a file named
proto/sfapi.proto
that looks like so:
Protocol Buffer
syntax
=
"proto3"
;
// The "google/protobuf" import folder provides several types that
// are included with protoc. This one is a representation of
// timestamps/dates.
import
"google/protobuf/timestamp.proto"
;
option
go_package
=
"proto"
;
service
Starfriends
{
// Get a single...