diff options
author | r <r@freesoftwareextremist.com> | 2019-12-17 20:17:25 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2019-12-17 20:17:25 +0000 |
commit | 59aad78f66cf58be7f88f2c0675f94a858163560 (patch) | |
tree | 95f00d18a8c847cdf4ee587e412de26960770a28 /model/app.go | |
parent | 3b50f40c081c499c2ecb8913b54186c622561d76 (diff) | |
download | bloat-59aad78f66cf58be7f88f2c0675f94a858163560.tar.gz bloat-59aad78f66cf58be7f88f2c0675f94a858163560.zip |
Use filesystem based kv store instead of sqlite
Diffstat (limited to 'model/app.go')
-rw-r--r-- | model/app.go | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/model/app.go b/model/app.go index 52ebdf5..89d656d 100644 --- a/model/app.go +++ b/model/app.go @@ -1,19 +1,40 @@ package model -import "errors" +import ( + "errors" + "strings" +) var ( ErrAppNotFound = errors.New("app not found") ) type App struct { - InstanceURL string - ClientID string - ClientSecret string + InstanceDomain string + InstanceURL string + ClientID string + ClientSecret string } type AppRepository interface { Add(app App) (err error) - Update(instanceURL string, clientID string, clientSecret string) (err error) - Get(instanceURL string) (app App, err error) + Get(instanceDomain string) (app App, err error) +} + +func (a *App) Marshal() []byte { + str := a.InstanceURL + "\n" + a.ClientID + "\n" + a.ClientSecret + return []byte(str) +} + +func (a *App) Unmarshal(instanceDomain string, data []byte) error { + str := string(data) + lines := strings.Split(str, "\n") + if len(lines) != 3 { + return errors.New("invalid data") + } + a.InstanceDomain = instanceDomain + a.InstanceURL = lines[0] + a.ClientID = lines[1] + a.ClientSecret = lines[2] + return nil } |