aboutsummaryrefslogtreecommitdiff
path: root/model/session.go
diff options
context:
space:
mode:
Diffstat (limited to 'model/session.go')
-rw-r--r--model/session.go34
1 files changed, 30 insertions, 4 deletions
diff --git a/model/session.go b/model/session.go
index 43628ee..94f527b 100644
--- a/model/session.go
+++ b/model/session.go
@@ -1,15 +1,18 @@
package model
-import "errors"
+import (
+ "errors"
+ "strings"
+)
var (
ErrSessionNotFound = errors.New("session not found")
)
type Session struct {
- ID string
- InstanceURL string
- AccessToken string
+ ID string
+ InstanceDomain string
+ AccessToken string
}
type SessionRepository interface {
@@ -21,3 +24,26 @@ type SessionRepository interface {
func (s Session) IsLoggedIn() bool {
return len(s.AccessToken) > 0
}
+
+func (s *Session) Marshal() []byte {
+ str := s.InstanceDomain + "\n" + s.AccessToken
+ return []byte(str)
+}
+
+func (s *Session) Unmarshal(id string, data []byte) error {
+ str := string(data)
+ lines := strings.Split(str, "\n")
+
+ size := len(lines)
+ if size == 1 {
+ s.InstanceDomain = lines[0]
+ } else if size == 2 {
+ s.InstanceDomain = lines[0]
+ s.AccessToken = lines[1]
+ } else {
+ return errors.New("invalid data")
+ }
+
+ s.ID = id
+ return nil
+}