将DumpResponse写入文件后解压缩

I have following code:

dump, err := httputil.DumpResponse(response, true)
ioutil.WriteFile(response.Request.Host+".txt", dump, 0644)

I creates following file example.com.txt:

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Accept-Ranges: bytes
Age: 0
Cache-Control: public
Content-Encoding: gzip
Content-Type: text/xml
Date: Sun, 01 Apr 2018 08:52:39 GMT
Last-Modified: Thu, 01 Mar 2018 13:30:10 GMT
Server: Microsoft-IIS/7.5
Vary: Accept-Encoding
Via: 1.1 varnish

8000
�      �`I�����B�⓿�O����?����...

How can I read gzipped content from the file now?

You can deserialize it back to http.Response, and then 'ungzip' body:

func main()  {
    file, _ := os.Open(`/home/your/path/file.txt`)
    response, _ := http.ReadResponse(bufio.NewReader(file), nil)
    reader, _ := gzip.NewReader(response.Body)
    ungzipped, _ := ioutil.ReadAll(reader)
    fmt.Println(string(ungzipped))
}