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 goes wrong.
Tip
To model remote method calls, you essentially create a struct
for the incoming arguments and a struct
for the return arguments.
Before continuing, see whether you can model the same request/response pair for the Validate
method...