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