-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform.go
47 lines (39 loc) · 851 Bytes
/
platform.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
package release
import (
"crypto/md5"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
type platform struct {
Name string `json:"name"`
URL string `json:"url"`
Digest string `json:"digest"`
}
func buildPlatform(ver, platformName, distDir, binName string, u uploader) (platform, error) {
f, err := os.Open(filepath.Join(distDir, platformName, binName))
if err != nil {
return platform{}, err
}
data, err := ioutil.ReadAll(f)
if err != nil {
return platform{}, err
}
f.Seek(0, io.SeekStart)
fullName := strings.Join([]string{ver, platformName, binName}, "/")
url, err := u.File(fullName, f)
if err != nil {
return platform{}, err
}
if err := f.Close(); err != nil {
return platform{}, err
}
return platform{
Name: platformName,
URL: url,
Digest: fmt.Sprintf("%x", md5.Sum(data)),
}, nil
}