-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.go
46 lines (36 loc) · 756 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"io"
"net/http"
"os"
"path"
"github.com/termie/go-shutil"
"github.com/kendfss/but"
)
func DownloadFiles(url, dataPath string) (err error) {
archivePath := path.Join(os.TempDir(), "master.zip")
// Create the file
out, err := os.Create(archivePath)
if err != nil {
return err
}
defer out.Close()
// Get the data
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
// Writer the body to file
_, err = io.Copy(out, resp.Body)
if err != nil {
return err
}
// Unzip
// err = unzip(archivePath, "/tmp")
err = unzipSource(archivePath, os.TempDir())
but.Must(err)
err = shutil.CopyTree(path.Join(os.TempDir(), "gitignore-main"), dataPath, nil)
but.Must(err)
return nil
}