Skip to content

Commit 9e0385e

Browse files
committed
Add downloadFile() function
1 parent eb12eaf commit 9e0385e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

make.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"io/ioutil"
88
"log"
9+
"net/http"
910
"os"
1011
"os/exec"
1112
"os/user"
@@ -75,6 +76,30 @@ func findVendorDirs(dir string) ([]string, error) {
7576
return vendorDirs, err
7677
}
7778

79+
func downloadFile(filename, url string) error {
80+
dst, err := os.Create(filename)
81+
if err != nil {
82+
return err
83+
}
84+
defer dst.Close()
85+
86+
resp, err := http.Get(url)
87+
if err != nil {
88+
return err
89+
}
90+
defer resp.Body.Close()
91+
if resp.StatusCode != 200 {
92+
return fmt.Errorf(resp.Status)
93+
}
94+
95+
_, err = io.Copy(dst, resp.Body)
96+
if err != nil {
97+
return err
98+
}
99+
100+
return nil
101+
}
102+
78103
// upstream describes the upstream repo we are about to package.
79104
type upstream struct {
80105
tarPath string // path to the generated orig tarball tempfile

0 commit comments

Comments
 (0)