aboutsummaryrefslogtreecommitdiff
path: root/sources.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-10-11 01:21:48 +0000
committerFuwn <[email protected]>2024-10-11 01:21:48 +0000
commitc74b01e0b88c2ed819b617e41692221f2e5acd3c (patch)
treeee1000ec8521b2964179f213998c59a30909414e /sources.go
downloadyae-c74b01e0b88c2ed819b617e41692221f2e5acd3c.tar.xz
yae-c74b01e0b88c2ed819b617e41692221f2e5acd3c.zip
feat: initial release
Diffstat (limited to 'sources.go')
-rw-r--r--sources.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/sources.go b/sources.go
new file mode 100644
index 0000000..1a2c0b5
--- /dev/null
+++ b/sources.go
@@ -0,0 +1,63 @@
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+ "os"
+)
+
+type Sources map[string]Source
+
+type Source struct {
+ Url string `json:"url"`
+ SHA256 string `json:"sha256"`
+ Unpack bool `json:"unpack"`
+}
+
+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)
+}