You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the responder, render.JSON() function takes in an "http.Request" object which will be used to get the http response status code
I'm customizing the behavior of the function, by wrapping it with a wrapper function in my project. So I can call one function to pass in the response body as well as the status code, like so
func (r *responder) JSON(w http.ResponseWriter, v interface{}, s int) {
// Write http response status
w.WriteHeader(s)
render.JSON(w, nil, v)
}
When "nil" is passed is shown above instead of an http.Request object, the function throws an error.
In the responder, render.JSON() function takes in an "http.Request" object which will be used to get the http response status code
I'm customizing the behavior of the function, by wrapping it with a wrapper function in my project. So I can call one function to pass in the response body as well as the status code, like so
When "nil" is passed is shown above instead of an http.Request object, the function throws an error.
Here is the test I wrote to test the wrapper:
I did some debugging, it seems like the error is caused by line 103 in JSON function in responder.go, which is the following:
How about adding a check for when the request object is nil, it skips this whole check and only writes the body to the buffer?
The text was updated successfully, but these errors were encountered: