Response is a library that generates output that follows carrot/restful-api-spec.
The output conforms to this structure:
{
"meta": {
"success": true,
"status_code": 200,
"status_text": "OK",
"error_details": "Invalid email"
},
"content": {
// ...
}
}
Dig into response.go for specifics, but this code sample covers all usage:
func (c *MyController) Index(w http.ResponseWriter, r *http.Request) {
resp := response.New(w)
defer resp.Output()
models, err := getModels()
if err != nil {
resp.SetErrorDetails(err.Error())
resp.setResult(http.StatusInternalServerError, nil)
return
}
resp.SetResult(http.StatusOK, models)
}