blob: b227e9b41349f7a1b427892063ac1d73d90cde83 (
plain) (
blame)
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
|
package main
import (
"encoding/json"
"fmt"
"os"
)
type Sources map[string]Source
type Source struct {
URI string `json:"url"`
SHA256 string `json:"sha256"`
Unpack bool `json:"unpack"`
Type string `json:"type"`
Version string `json:"version,omitempty"`
URITemplate string `json:"uri_template,omitempty"`
TagPredicate string `json:"tag_predicate,omitempty"`
TrimTagPrefix string `json:"trim_tag_prefix,omitempty"`
Pinned bool `json:"pinned,omitempty"`
}
func (s *Sources) EnsureLoaded() error {
return nil
}
func (s *Sources) Add(name string, d Source) error {
if s.Exists(name) {
return fmt.Errorf("source already exists")
}
(*s)[name] = d
return nil
}
func (s *Sources) Exists(name string) bool {
_, ok := (*s)[name]
return ok
}
func (s *Sources) Drop(url string) {
delete((*s), url)
}
func (s *Sources) Save(path string) error {
file, err := os.Create(path)
if err != nil {
return err
}
encoder := json.NewEncoder(file)
encoder.SetIndent("", " ")
return encoder.Encode(s)
}
func (s *Sources) Load(path string) error {
file, err := os.Open(path)
if err != nil {
return err
}
return json.NewDecoder(file).Decode(s)
}
|