-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.go
59 lines (46 loc) · 1.13 KB
/
kernel.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
47
48
49
50
51
52
53
54
55
56
57
58
59
package api
import (
"context"
"fmt"
"io"
"net/http"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/spf13/afero"
)
type Kernel struct {
SubPath string
URL string
Size int64
}
func (k Kernel) GetName() string {
return semverOrURL(k.URL)
}
func (k Kernel) GetSubPath() string {
return k.SubPath
}
func (k Kernel) GetSize() int64 {
return k.Size
}
func (k Kernel) HasMD5() bool {
return false
}
func (k Kernel) DownloadMD5(ctx context.Context, target *afero.File, c *http.Client, s3downloader *s3manager.Downloader) (string, error) {
return "", nil
}
func (k Kernel) Download(ctx context.Context, target afero.File, c *http.Client, s3downloader *s3manager.Downloader) (int64, error) {
req, err := http.NewRequest(http.MethodGet, k.URL, nil)
if err != nil {
return 0, fmt.Errorf("unable to create get request:%w", err)
}
req = req.WithContext(ctx)
resp, err := c.Do(req)
if err != nil {
return 0, fmt.Errorf("kernel download error:%w", err)
}
defer resp.Body.Close()
n, err := io.Copy(target, resp.Body)
if err != nil {
return 0, fmt.Errorf("kernel download error:%w", err)
}
return n, nil
}