bloat/repository/appRepository.go

34 lines
552 B
Go
Raw Normal View History

2019-12-13 20:08:26 +02:00
package repository
import (
"web/kv"
2019-12-13 20:08:26 +02:00
"web/model"
)
type appRepository struct {
db *kv.Database
2019-12-13 20:08:26 +02:00
}
func NewAppRepository(db *kv.Database) *appRepository {
2019-12-13 20:08:26 +02:00
return &appRepository{
db: db,
}
2019-12-13 20:08:26 +02:00
}
func (repo *appRepository) Add(a model.App) (err error) {
err = repo.db.Set(a.InstanceDomain, a.Marshal())
2019-12-13 20:08:26 +02:00
return
}
func (repo *appRepository) Get(instanceDomain string) (a model.App, err error) {
data, err := repo.db.Get(instanceDomain)
2019-12-13 20:08:26 +02:00
if err != nil {
err = model.ErrAppNotFound
return
}
err = a.Unmarshal(instanceDomain, data)
2019-12-13 20:08:26 +02:00
return
}