tgpl

The Go Programming Language - Solutions
Log | Files | Refs

commit 23a9ebe7fe313f4af9db6600cd825074a23e4a28
parent 22818513792d88d305d0e3c769cabcef4f110969
Author: zerous Naveen Narayanan <zerous@nocebo.space>
Date:   Fri,  1 Mar 2019 01:58:37 +0100

Add exercise 1.7 solution

Diffstat:
Aexercise-1-7.go | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/exercise-1-7.go b/exercise-1-7.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "io" + "net/http" + "os" +) + +func main() { + for _, url := range os.Args[1:] { + resp, err := http.Get(url) + if err != nil { + fmt.Fprintf(os.Stderr, "fetch: %v\n", err) + os.Exit(1) + } + if _, err := io.Copy(os.Stdout, resp.Body); err != nil { + resp.Body.Close() + fmt.Fprintf(os.Stderr, "io.Copy\n") + os.Exit(1) + } + } +} + + + \ No newline at end of file