This repository has been archived by the owner on Aug 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
64 lines (57 loc) · 1.93 KB
/
info.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
60
61
62
63
64
// info.go // This file implements binInfo, which `info` and `update` use //>
package main
import (
"fmt"
)
// BinaryInfo struct holds binary metadata used in main.go for the `info`, `update`, `list` functionality
type BinaryInfo struct {
Name string `json:"name"`
Description string `json:"description"`
Repo string `json:"repo_url"`
ModTime string `json:"build_date"`
Version string `json:"repo_version"`
Updated string `json:"repo_updated"`
Size string `json:"size"`
Extras string `json:"extra_bins"`
SHA256 string `json:"sha256"`
Source string `json:"download_url"`
}
func findBinaryInfo(metadata []map[string]interface{}, binaryName string) (BinaryInfo, bool) {
for _, binMap := range metadata {
if name, ok := binMap["name"].(string); ok && name == binaryName {
description, _ := binMap["description"].(string)
repo, _ := binMap["repo_url"].(string)
buildDate, _ := binMap["build_date"].(string)
version, _ := binMap["repo_version"].(string)
updated, _ := binMap["repo_updated"].(string)
size, _ := binMap["size"].(string)
extras, _ := binMap["extra_bins"].(string)
sha256, _ := binMap["sha256"].(string)
source, _ := binMap["download_url"].(string)
return BinaryInfo{
Name: name,
Description: description,
Repo: repo,
ModTime: buildDate,
Version: version,
Updated: updated,
Size: size,
Extras: extras,
SHA256: sha256,
Source: source,
}, true
}
}
return BinaryInfo{}, false
}
func getBinaryInfo(binaryName string) (*BinaryInfo, error) {
var metadata []map[string]interface{}
if err := fetchJSON(RNMetadataURL, &metadata); err != nil {
return nil, err
}
binInfo, found := findBinaryInfo(metadata, binaryName)
if !found {
return nil, fmt.Errorf("error: info for the requested binary ('%s') not found in the metadata.json file", binaryName)
}
return &binInfo, nil
}