Modeling method calls with requests and responses

Since our service will be exposed through various transport protocols, we will need a way to model the requests and responses in and out of our service. We will do this by adding a struct for each type of message our service will accept or return.

In order for somebody to call the Hash method and then receive the hashed password as a response, we'll need to add the following two structures to service.go:

type hashRequest struct { 
  Password string `json:"password"` 
} 
type hashResponse struct { 
  Hash string `json:"hash"` 
  Err  string `json:"err,omitempty"` 
} 

The hashRequest type contains a single field, the password, and the hashResponse has the resulting hash and an Err string field in case something ...

Get Go: Design Patterns for Real-World Projects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.