| 1 |
package cache |
| 2 |
|
| 3 |
import ( |
| 4 |
"encoding/json" |
| 5 |
|
| 6 |
"git.sr.ht/~rockorager/go-jmap" |
| 7 |
) |
| 8 |
|
| 9 |
func (c *JMAPCache) GetSession() (*jmap.Session, error) { |
| 10 |
buf, err := c.get(sessionKey) |
| 11 |
if err != nil { |
| 12 |
return nil, err |
| 13 |
} |
| 14 |
s := new(jmap.Session) |
| 15 |
err = json.Unmarshal(buf, s) |
| 16 |
if err != nil { |
| 17 |
return nil, err |
| 18 |
} |
| 19 |
return s, nil |
| 20 |
} |
| 21 |
|
| 22 |
func (c *JMAPCache) PutSession(s *jmap.Session) error { |
| 23 |
buf, err := json.Marshal(s) |
| 24 |
if err != nil { |
| 25 |
return err |
| 26 |
} |
| 27 |
return c.put(sessionKey, buf) |
| 28 |
} |
| 29 |
|
| 30 |
func (c *JMAPCache) DeleteSession() error { |
| 31 |
return c.delete(sessionKey) |
| 32 |
} |
| 33 |
|
| 34 |
const sessionKey = "session" |