From 88d16d86d5fd428b0034b2dbaf00d5b2caed1d54 Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Fri, 8 Nov 2019 11:12:20 +0300 Subject: [PATCH] refactor: handle err with fprintln io png detector ifaces --- interfaces/15-png-detector/main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/interfaces/15-png-detector/main.go b/interfaces/15-png-detector/main.go index 6686d32..bc88115 100644 --- a/interfaces/15-png-detector/main.go +++ b/interfaces/15-png-detector/main.go @@ -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)