aboutsummaryrefslogtreecommitdiff
path: root/repo/appRepo.go
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2020-01-28 17:51:00 +0000
committerr <r@freesoftwareextremist.com>2020-01-28 17:58:29 +0000
commit2af37d47783aac8c650ffd1578e2297b5784c73d (patch)
tree7b5c7a4b2fa530285bfaa16324e818d97dd00408 /repo/appRepo.go
parent57d2a4288b02fd1245ee85ae629649798578cf6c (diff)
downloadbloat-2af37d47783aac8c650ffd1578e2297b5784c73d.tar.gz
bloat-2af37d47783aac8c650ffd1578e2297b5784c73d.zip
Refactor everything
Diffstat (limited to 'repo/appRepo.go')
-rw-r--r--repo/appRepo.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/repo/appRepo.go b/repo/appRepo.go
new file mode 100644
index 0000000..6338c4a
--- /dev/null
+++ b/repo/appRepo.go
@@ -0,0 +1,42 @@
+package repo
+
+import (
+ "encoding/json"
+
+ "bloat/kv"
+ "bloat/model"
+)
+
+type appRepo struct {
+ db *kv.Database
+}
+
+func NewAppRepo(db *kv.Database) *appRepo {
+ return &appRepo{
+ db: db,
+ }
+}
+
+func (repo *appRepo) Add(a model.App) (err error) {
+ data, err := json.Marshal(a)
+ if err != nil {
+ return
+ }
+ err = repo.db.Set(a.InstanceDomain, data)
+ return
+}
+
+func (repo *appRepo) Get(instanceDomain string) (a model.App, err error) {
+ data, err := repo.db.Get(instanceDomain)
+ if err != nil {
+ err = model.ErrAppNotFound
+ return
+ }
+
+ err = json.Unmarshal(data, &a)
+ if err != nil {
+ return
+ }
+
+ return
+}