From 5e6396656527782bb2893253480804a312399ad1 Mon Sep 17 00:00:00 2001 From: Xavier Petit <32063953+xpetit@users.noreply.github.com> Date: Mon, 13 Apr 2020 19:09:19 +0200 Subject: [PATCH] Refactor cat solution --- tests/go/solutions/cat/main.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/go/solutions/cat/main.go b/tests/go/solutions/cat/main.go index 02d8a2291..04d0a21a5 100644 --- a/tests/go/solutions/cat/main.go +++ b/tests/go/solutions/cat/main.go @@ -7,18 +7,17 @@ import ( ) func main() { - size := len(os.Args) - if size == 1 { + if len(os.Args) == 1 { if _, err := io.Copy(os.Stdout, os.Stdin); err != nil { panic(err) } } else { - for i := 1; i < size; i++ { - data, err := ioutil.ReadFile(os.Args[i]) + for _, arg := range os.Args[1:] { + data, err := ioutil.ReadFile(arg) if err != nil { panic(err) } - fmt.Print(string(data)) + os.Stdout.Write(data) } } }