mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2025-05-12 14:58:45 +00:00
Refactor everything
This commit is contained in:
parent
57d2a4288b
commit
2af37d4778
26 changed files with 1320 additions and 1361 deletions
|
@ -1,42 +0,0 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"bloat/kv"
|
||||
"bloat/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) {
|
||||
data, err := json.Marshal(a)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = repo.db.Set(a.InstanceDomain, data)
|
||||
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 = json.Unmarshal(data, &a)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue