aboutsummaryrefslogtreecommitdiffstats
path: root/worker/jmap/cache/session.go
blob: 3769979a1d106f5c8c16607515cc199c604b760c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package cache

import (
	"encoding/json"

	"git.sr.ht/~rockorager/go-jmap"
)

func (c *JMAPCache) GetSession() (*jmap.Session, error) {
	buf, err := c.get(sessionKey)
	if err != nil {
		return nil, err
	}
	s := new(jmap.Session)
	err = json.Unmarshal(buf, s)
	if err != nil {
		return nil, err
	}
	return s, nil
}

func (c *JMAPCache) PutSession(s *jmap.Session) error {
	buf, err := json.Marshal(s)
	if err != nil {
		return err
	}
	return c.put(sessionKey, buf)
}

func (c *JMAPCache) DeleteSession() error {
	return c.delete(sessionKey)
}

const sessionKey = "session"