refactor: handle err with fprintln io png detector ifaces

This commit is contained in:
Inanc Gumus 2019-11-08 11:12:20 +03:00
parent cf66e4b720
commit 88d16d86d5

View File

@ -12,25 +12,26 @@ import (
"bytes"
"fmt"
"io"
"log"
"net/http"
"os"
)
func main() {
// initiate the transmission channel (http connection) to the webserver.
resp, err := http.Get("https://inancgumus.github.com/x/rosie.unknown")
if err != nil {
log.Fatal(err)
fmt.Fprintln(os.Stderr, err)
return
}
// close it for keep-alive header.
// so the http package can reuse the connection.
// close it so the http package can reuse the connection.
defer resp.Body.Close()
// resp.Body here is an io.ReadCloser: Read() + Close() methods.
// but in the transfer function it's an io.Reader: Only the Read() method.
n, err := transfer(resp.Body)
if err != nil {
log.Fatal(err)
fmt.Fprintln(os.Stderr, err)
return
}
fmt.Printf("%d bytes transferred.\n", n)