aboutsummaryrefslogtreecommitdiff
path: root/repository/appRepository.go
blob: 00ef64d0e87b902fe4522f3c461c94e5dcd17a80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package repository

import (
	"web/kv"
	"web/model"
)

type appRepository struct {
	db *kv.Database
}

func NewAppRepository(db *kv.Database) *appRepository {
	return &appRepository{
		db: db,
	}
}

func (repo *appRepository) Add(a model.App) (err error) {
	err = repo.db.Set(a.InstanceDomain, a.Marshal())
	return
}

func (repo *appRepository) Get(instanceDomain string) (a model.App, err error) {
	data, err := repo.db.Get(instanceDomain)
	if err != nil {
		err = model.ErrAppNotFound
		return
	}

	err = a.Unmarshal(instanceDomain, data)

	return
}