记录响应主体以进行日志记录

Please see this playground. I'm trying to provide access logging to our logging platform, but I'm kind of stuck now. I have managed to get the status code of the response, but now I'm also interested in the response content-length. But unfortunately I really don't have a clue of how to get/extract the content length by using the wrapped-handler mechanism. Any help is highly appreciated.

You already have a custom ResponseWriter, so just add a function something like this to override Write and store the amount written by the underlying writer:

https://play.golang.org/p/dwWEs5KI_wM

func (lrw *loggingResponseWriter) Write(b []byte) (int, error) {
    n,err := lrw.ResponseWriter.Write(b)
    lrw.written  = lrw.written + n
    return n,err
}