方法是body重新赋值,
bodyBytes, _ := ioutil.ReadAll(req.Body)
req.Body.Close() // must close
req.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
看了三个网页,都是这样做的:
https://stackoverflow.com/questions/46948050/how-to-read-response-body-twice-in-golang-middleware
https://medium.com/@xoen/golang-read-from-an-io-readwriter-without-loosing-its-content-2c6911805361
http://blog.manugarri.com/how-to-reuse-http-response-body-in-golang/