Hi All,
we copy response body from a call into responseWriter w.
my question is:
a) if err!=nil, it is possible that w is also not nil? Or no: if err!=nil then w is nil.
b) the following order is correct?
I would send response body (which is in src (resp.Body type io.ReadCloser)) as xml content type with OK status.
And if error happens by io.Copy, then send a json body with status code 599.
w.Header().Set("Content-Type", "application/xml")
_, err:=io.Copy(w,src)
if err!=nil{
re := &res{ Message: "Error happened",}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(599) //sample status code
err = json.NewEncoder(w).Encode(re)
}//if