feat: add status code in response
This commit is contained in:
parent
d0f5277bf4
commit
4e25c647b2
|
@ -11,6 +11,7 @@ type ResponseData map[string]interface{}
|
||||||
// Response represents an API response to be sent
|
// Response represents an API response to be sent
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Data ResponseData
|
Data ResponseData
|
||||||
|
Status int
|
||||||
Headers http.Header
|
Headers http.Header
|
||||||
Err Error
|
Err Error
|
||||||
}
|
}
|
||||||
|
@ -18,8 +19,10 @@ type Response struct {
|
||||||
// NewResponse creates an empty response
|
// NewResponse creates an empty response
|
||||||
func NewResponse() *Response {
|
func NewResponse() *Response {
|
||||||
return &Response{
|
return &Response{
|
||||||
|
Status: http.StatusOK,
|
||||||
Data: make(ResponseData),
|
Data: make(ResponseData),
|
||||||
Err: ErrorFailure(),
|
Err: ErrorFailure(),
|
||||||
|
Headers: make(http.Header),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
util.go
1
util.go
|
@ -87,6 +87,7 @@ func (s *Server) extractParameters(store *reqdata.Store, methodParam map[string]
|
||||||
|
|
||||||
// Prints an HTTP response
|
// Prints an HTTP response
|
||||||
func httpPrint(r http.ResponseWriter, res *api.Response) {
|
func httpPrint(r http.ResponseWriter, res *api.Response) {
|
||||||
|
r.WriteHeader(res.Status)
|
||||||
|
|
||||||
// write this json
|
// write this json
|
||||||
jsonResponse, _ := json.Marshal(res)
|
jsonResponse, _ := json.Marshal(res)
|
||||||
|
|
Loading…
Reference in New Issue