mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2025-05-02 10:04:22 +00:00
Refactor everything
This commit is contained in:
parent
57d2a4288b
commit
2af37d4778
26 changed files with 1320 additions and 1361 deletions
42
repo/appRepo.go
Normal file
42
repo/appRepo.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"bloat/kv"
|
||||
"bloat/model"
|
||||
)
|
||||
|
||||
type appRepo struct {
|
||||
db *kv.Database
|
||||
}
|
||||
|
||||
func NewAppRepo(db *kv.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
|
||||
}
|
42
repo/sessionRepo.go
Normal file
42
repo/sessionRepo.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"bloat/kv"
|
||||
"bloat/model"
|
||||
)
|
||||
|
||||
type sessionRepo struct {
|
||||
db *kv.Database
|
||||
}
|
||||
|
||||
func NewSessionRepo(db *kv.Database) *sessionRepo {
|
||||
return &sessionRepo{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (repo *sessionRepo) Add(s model.Session) (err error) {
|
||||
data, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = repo.db.Set(s.ID, data)
|
||||
return
|
||||
}
|
||||
|
||||
func (repo *sessionRepo) Get(id string) (s model.Session, err error) {
|
||||
data, err := repo.db.Get(id)
|
||||
if err != nil {
|
||||
err = model.ErrSessionNotFound
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(data, &s)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue