I try to read the request body via request.GetBody(), since I need to read the same request body more than once, but I always get the error below. I checked if the req.body is empty, but it is not. I cant even call req.GetBody(). My Go version is 1.8.1.
func read(res http.ResponseWriter, req *http.Request) {
_, err := req.GetBody()
if err != nil {
res.Write([]byte(err.Error()))
return
}
}
Error:
http: panic serving [::1]:53174: runtime error: invalid memory address or nil pointer dereference