mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2025-05-08 12:58:44 +00:00
Use json format for app and session repo
This commit is contained in:
parent
a25d64a078
commit
e73eb1162a
4 changed files with 34 additions and 56 deletions
|
@ -1,6 +1,7 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"web/kv"
|
||||
"web/model"
|
||||
)
|
||||
|
@ -16,7 +17,11 @@ func NewAppRepository(db *kv.Database) *appRepository {
|
|||
}
|
||||
|
||||
func (repo *appRepository) Add(a model.App) (err error) {
|
||||
err = repo.db.Set(a.InstanceDomain, a.Marshal())
|
||||
data, err := json.Marshal(a)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = repo.db.Set(a.InstanceDomain, data)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -27,7 +32,10 @@ func (repo *appRepository) Get(instanceDomain string) (a model.App, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
err = a.Unmarshal(instanceDomain, data)
|
||||
err = json.Unmarshal(data, &a)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"web/kv"
|
||||
"web/model"
|
||||
)
|
||||
|
@ -16,7 +17,11 @@ func NewSessionRepository(db *kv.Database) *sessionRepository {
|
|||
}
|
||||
|
||||
func (repo *sessionRepository) Add(s model.Session) (err error) {
|
||||
err = repo.db.Set(s.ID, s.Marshal())
|
||||
data, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = repo.db.Set(s.ID, data)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -27,14 +32,19 @@ func (repo *sessionRepository) Update(id string, accessToken string) (err error)
|
|||
}
|
||||
|
||||
var s model.Session
|
||||
err = s.Unmarshal(id, data)
|
||||
err = json.Unmarshal(data, &s)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
s.AccessToken = accessToken
|
||||
|
||||
return repo.db.Set(id, s.Marshal())
|
||||
data, err = json.Marshal(s)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return repo.db.Set(id, data)
|
||||
}
|
||||
|
||||
func (repo *sessionRepository) Get(id string) (s model.Session, err error) {
|
||||
|
@ -44,7 +54,10 @@ func (repo *sessionRepository) Get(id string) (s model.Session, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
err = s.Unmarshal(id, data)
|
||||
err = json.Unmarshal(data, &s)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue