From 1a1804724693e8a4f1055eaa6f7a388708ffbd39 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Thu, 12 Nov 2020 10:55:47 +0100 Subject: [PATCH] Make downloader response public --- downloader.go | 8 ++++---- downloader_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/downloader.go b/downloader.go index 4bb059b..4f2fc8b 100644 --- a/downloader.go +++ b/downloader.go @@ -19,7 +19,7 @@ import ( type Downloader struct { URL string Done chan bool - resp *http.Response + Resp *http.Response out *os.File completed int64 completedLock sync.Mutex @@ -38,7 +38,7 @@ const ( // Close the download func (d *Downloader) Close() error { err1 := d.out.Close() - err2 := d.resp.Body.Close() + err2 := d.Resp.Body.Close() if err1 != nil { return fmt.Errorf("closing output file: %s", err1) } @@ -74,7 +74,7 @@ func (d *Downloader) RunAndPoll(poll func(current int64), interval time.Duration // AsyncRun starts the downloader copy-loop. This function is supposed to be run // on his own go routine because it sends a confirmation on the Done channel func (d *Downloader) AsyncRun() { - in := d.resp.Body + in := d.Resp.Body buff := [4096]byte{} for { n, err := in.Read(buff[:]) @@ -170,7 +170,7 @@ func DownloadWithConfig(file string, reqURL string, config Config, options ...Do d := &Downloader{ URL: reqURL, Done: make(chan bool), - resp: resp, + Resp: resp, out: f, completed: completed, size: resp.ContentLength + completed, diff --git a/downloader_test.go b/downloader_test.go index 7ddea40..80bd645 100644 --- a/downloader_test.go +++ b/downloader_test.go @@ -168,7 +168,7 @@ func TestApplyUserAgentHeaderUsingConfig(t *testing.T) { require.NoError(t, err) testEchoBody := echoBody{} - body, err := ioutil.ReadAll(d.resp.Body) + body, err := ioutil.ReadAll(d.Resp.Body) require.NoError(t, err) err = json.Unmarshal(body, &testEchoBody) require.NoError(t, err)