Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

Unary RPCs

A unary RPC is equivalent to the request-response model that's used in traditional RESTful APIs. In the following example, we are defining a service with the name AccountService that exposes a CreateAccount method that receives CreateAccountRequest as input and returns a CreateAccountResponse to the caller:

message CreateAccountRequest {  string user_name = 1;  string password = 2;  string email = 3;}message CreateAccountResponse {  string account_id = 1;}service AccountService {  rpc CreateAccount (CreateAccountRequest) returns (CreateAccountResponse);}

Defining the server handler is also quite similar to a regular RESTful API. Consider the following code:

var _ AccountServiceServer = (*server)(nil)func (*server) CreateAccount(_ ...
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.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content