From 4e22b46850463540e8f92ce4e6c945539a780d56 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Tue, 17 Jul 2018 08:44:35 -0700 Subject: [PATCH] refactor download file to utils --- .../experiment/utils/utils.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 aws-experiment-launch/experiment/utils/utils.go diff --git a/aws-experiment-launch/experiment/utils/utils.go b/aws-experiment-launch/experiment/utils/utils.go new file mode 100644 index 000000000..a50b2f8f4 --- /dev/null +++ b/aws-experiment-launch/experiment/utils/utils.go @@ -0,0 +1,29 @@ +package utils + +import ( + "io" + "net/http" + "os" +) + +func DownloadFile(filepath string, url string) { + // Create the file + out, err := os.Create(filepath) + if err != nil { + panic(err) + } + defer out.Close() + + // Get the data + resp, err := http.Get(url) + if err != nil { + panic(err) + } + defer resp.Body.Close() + + // Write the body to file + _, err = io.Copy(out, resp.Body) + if err != nil { + panic(err) + } +}