diff options
| -rw-r--r-- | internal/fetch/fetch.go | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/internal/fetch/fetch.go b/internal/fetch/fetch.go index f22139d..73ecffa 100644 --- a/internal/fetch/fetch.go +++ b/internal/fetch/fetch.go @@ -1,7 +1,6 @@ package fetch import ( - "bufio" "fmt" "io" "net/http" @@ -9,10 +8,10 @@ import ( ) // Fetch makes a GET request to rawURL, returning the HTML contents of -// that webpage in the form of an [io.Reader]. An error is also -// returned. The parameter timeoutSecs is passed directly to the -// [http.Client.Timeout] field of the client making the request. -func Fetch(rawURL string, timeoutSecs int) (io.Reader, error) { +// that webpage as a []byte. An error is also returned. The parameter +// timeoutSecs is passed directly to the [http.Client.Timeout] field +// of the client making the request. +func Fetch(rawURL string, timeoutSecs int) ([]byte, error) { client := http.Client{ Timeout: time.Duration(timeoutSecs) * time.Second, } @@ -32,5 +31,10 @@ func Fetch(rawURL string, timeoutSecs int) (io.Reader, error) { return nil, fmt.Errorf("status for %s for %s: %s", http.MethodGet, rawURL, resp.Status) } - return bufio.NewReader(resp.Body), nil + htmlBytes, err := io.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("can't dump response body into byte slice") + } + + return htmlBytes, nil } |
