mirror of
https://git.freesoftwareextremist.com/bloat
synced 2024-11-10 00:24:12 +00:00
42 lines
604 B
Go
42 lines
604 B
Go
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
|
|
}
|