-
Notifications
You must be signed in to change notification settings - Fork 0
/
repos.go
85 lines (75 loc) · 1.48 KB
/
repos.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package repos
import (
"context"
"encoding/json"
"net/http"
"time"
)
type Arch struct {
Idx string `json:"idx"`
Location string `json:"location"`
Kmp []string `json:"kmp"`
}
type Repo struct {
Idx string `json:"idx"`
Amd64 Arch `json:"amd64"`
}
type Distribution struct {
Idx string `json:"idx"`
Drbd9 Repo `json:"drbd-9"`
Drbd90 Repo `json:"drbd-9.0"`
}
type Repos struct {
About struct {
Created time.Time `json:"created"`
} `json:"about"`
Content struct {
Rhel7 Distribution `json:"rhel7"`
Rhel8 Distribution `json:"rhel8"`
Rhel9 Distribution `json:"rhel9"`
} `json:"content"`
}
func Get(ctx context.Context, pkgUrl string) (Repos, error) {
var repoinfo Repos
req, err := http.NewRequestWithContext(ctx, http.MethodGet, pkgUrl, nil)
if err != nil {
return repoinfo, err
}
r, err := http.DefaultClient.Do(req)
if err != nil {
return repoinfo, err
}
defer r.Body.Close()
if err := json.NewDecoder(r.Body).Decode(&repoinfo); err != nil {
return repoinfo, err
}
return repoinfo, nil
}
func (rs *Repos) GetKmps(repo, dist, arch string) []string {
var d Distribution
switch dist {
case "rhel7":
d = rs.Content.Rhel7
case "rhel8":
d = rs.Content.Rhel8
case "rhel9":
d = rs.Content.Rhel9
default:
return []string{}
}
var r Repo
switch repo {
case "drbd-9":
r = d.Drbd9
case "drbd-9.0":
r = d.Drbd90
default:
return []string{}
}
switch arch {
case "amd64":
return r.Amd64.Kmp
default:
return []string{}
}
}