feat: add status code in response

This commit is contained in:
Adrien Marquès 2019-05-01 16:40:26 +02:00
parent d0f5277bf4
commit 4e25c647b2
2 changed files with 6 additions and 2 deletions

View File

@ -11,6 +11,7 @@ type ResponseData map[string]interface{}
// Response represents an API response to be sent
type Response struct {
Data ResponseData
Status int
Headers http.Header
Err Error
}
@ -18,8 +19,10 @@ type Response struct {
// NewResponse creates an empty response
func NewResponse() *Response {
return &Response{
Data: make(ResponseData),
Err: ErrorFailure(),
Status: http.StatusOK,
Data: make(ResponseData),
Err: ErrorFailure(),
Headers: make(http.Header),
}
}

View File

@ -87,6 +87,7 @@ func (s *Server) extractParameters(store *reqdata.Store, methodParam map[string]
// Prints an HTTP response
func httpPrint(r http.ResponseWriter, res *api.Response) {
r.WriteHeader(res.Status)
// write this json
jsonResponse, _ := json.Marshal(res)