From 4e25c647b236b0babf929139eb4d81adf13f22f3 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 1 May 2019 16:40:26 +0200 Subject: [PATCH] feat: add status code in response --- api/response.go | 7 +++++-- util.go | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/response.go b/api/response.go index 2b2d96e..a6ea101 100644 --- a/api/response.go +++ b/api/response.go @@ -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), } } diff --git a/util.go b/util.go index e371623..305304d 100644 --- a/util.go +++ b/util.go @@ -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)