mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-23 07:23:00 +00:00
fa27d9c6eb
- Remove separate auth/logging and merge them into transport.go - Add helper function for http handlers
43 lines
610 B
Go
43 lines
610 B
Go
package repo
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"bloat/util"
|
|
"bloat/model"
|
|
)
|
|
|
|
type appRepo struct {
|
|
db *util.Database
|
|
}
|
|
|
|
func NewAppRepo(db *util.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
|
|
}
|