(new): rich message support
(fix): runtime reliability (tests): regression coverage (doc): v1.1 release notes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package laniakea
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"maps"
|
||||
"sync"
|
||||
@@ -131,18 +132,17 @@ type SceneSession struct {
|
||||
Scene string
|
||||
// Step is the current step name inside the active scene.
|
||||
Step string
|
||||
// data stores opaque session payload bytes, typically JSON.
|
||||
data []byte
|
||||
}
|
||||
|
||||
// SetData stores arbitrary opaque session data.
|
||||
func (s *SceneSession) SetData(data []byte) {
|
||||
s.data = data
|
||||
s.data = bytes.Clone(data)
|
||||
}
|
||||
|
||||
// GetData returns the raw session data payload.
|
||||
func (s *SceneSession) GetData() []byte {
|
||||
return s.data
|
||||
return bytes.Clone(s.data)
|
||||
}
|
||||
|
||||
// HasData reports whether the session has a non-empty data payload.
|
||||
@@ -198,6 +198,7 @@ func (s *MemorySessionStore) Get(key string) (SceneSession, error) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
if session, ok := s.store[key]; ok {
|
||||
session.data = bytes.Clone(session.data)
|
||||
return session, nil
|
||||
}
|
||||
return SceneSession{}, nil
|
||||
@@ -205,6 +206,7 @@ func (s *MemorySessionStore) Get(key string) (SceneSession, error) {
|
||||
|
||||
// Set stores session under key.
|
||||
func (s *MemorySessionStore) Set(key string, session SceneSession) error {
|
||||
session.data = bytes.Clone(session.data)
|
||||
s.mu.Lock()
|
||||
s.store[key] = session
|
||||
s.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user