diff options
Diffstat (limited to 'repository')
-rw-r--r-- | repository/appRepository.go | 12 | ||||
-rw-r--r-- | repository/sessionRepository.go | 21 |
2 files changed, 27 insertions, 6 deletions
diff --git a/repository/appRepository.go b/repository/appRepository.go index 00ef64d..cfa7950 100644 --- a/repository/appRepository.go +++ b/repository/appRepository.go @@ -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 } diff --git a/repository/sessionRepository.go b/repository/sessionRepository.go index 6c26313..d5f399a 100644 --- a/repository/sessionRepository.go +++ b/repository/sessionRepository.go @@ -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 } |