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