-
Notifications
You must be signed in to change notification settings - Fork 30
/
shims.go
56 lines (48 loc) · 1022 Bytes
/
shims.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
package main
import (
"encoding/json"
"fmt"
"os"
)
type Shim struct {
URL string `json:"url"`
Codename string `json:"codename"`
}
type ShimMirror struct {
Name string `json:"name"`
Shims []Shim `json:"shims"`
}
// resolved shim for a codename
type ResolvedShim struct {
Codename string
Mirror string `json:"mirror"`
URL string `json:"url"`
}
func getShims(mirrors []ShimMirror, codename string) []ResolvedShim {
res := []ResolvedShim{}
for i := range mirrors {
m := &mirrors[i]
for si := range m.Shims {
if m.Shims[si].Codename == codename {
res = append(res, ResolvedShim{
Codename: codename,
Mirror: m.Name,
URL: m.Shims[si].URL,
})
}
}
}
return res
}
func loadShimMirrors() []ShimMirror {
f, err := os.Open("shim_mirrors.json")
mirrors := []ShimMirror{}
if err == nil {
err = json.NewDecoder(f).Decode(&mirrors)
}
if err != nil {
fmt.Fprintf(os.Stderr, "Could not parse sh1mmer mirrors: %v\n", err)
os.Exit(1)
}
return mirrors
}