Files
aerc-fork-mirror/worker/jmap/cache/session.go
Tim Culverhouse f6e3a21db5 jmap: cache session as json
The gob encoder requires registration of types used during encoding.
There are several types defined in the Session object that don't
directly or indirectly get registered with gob. As a result, the session
object never actually gets cached, requiring an authentication step
which is often unnecessary.

Use json encoding for this object to provide a simpler serialization
path.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
2023-08-24 14:14:44 +02:00

35 lines
572 B
Go

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"