aboutsummaryrefslogtreecommitdiff
path: root/state/memory_state.go
diff options
context:
space:
mode:
Diffstat (limited to 'state/memory_state.go')
-rw-r--r--state/memory_state.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/state/memory_state.go b/state/memory_state.go
index 95c7318..97ecad1 100644
--- a/state/memory_state.go
+++ b/state/memory_state.go
@@ -1,7 +1,7 @@
1package state 1package state
2 2
3import ( 3import (
4"context" 4 "context"
5) 5)
6 6
7type memoryStateValue struct { 7type memoryStateValue struct {
@@ -13,7 +13,7 @@ func (m *memoryStateValue) Value(ctx context.Context) (any, error) {
13 kg := m.backend.currentGroupKey 13 kg := m.backend.currentGroupKey
14 key := m.backend.currentKey 14 key := m.backend.currentKey
15 ns := m.backend.currentNamespace 15 ns := m.backend.currentNamespace
16 if kgMap, exist := m.backend.states[m.stateName][kg][key]; exist { 16 if kgMap, ok := m.backend.states[m.stateName][kg][key]; ok {
17 if v, hasKey := kgMap[ns]; hasKey { 17 if v, hasKey := kgMap[ns]; hasKey {
18 return v, nil 18 return v, nil
19 } 19 }
@@ -26,10 +26,15 @@ func (m *memoryStateValue) Update(ctx context.Context, newVal any) (any, error)
26 kg := m.backend.currentGroupKey 26 kg := m.backend.currentGroupKey
27 key := m.backend.currentKey 27 key := m.backend.currentKey
28 ns := m.backend.currentNamespace 28 ns := m.backend.currentNamespace
29 if _, exists := m.backend.states[m.stateName][kg][key]; !exists { 29
30 if _, ok := m.backend.states[m.stateName][kg]; !ok {
30 m.backend.states[m.stateName][kg] = make(map[string]map[any]any) 31 m.backend.states[m.stateName][kg] = make(map[string]map[any]any)
31 } 32 }
32 33
34 if _, ok := m.backend.states[m.stateName][kg][key]; !ok {
35 m.backend.states[m.stateName][kg][key] = make(map[any]any)
36 }
37
33 m.backend.states[m.stateName][kg][key][ns] = newVal 38 m.backend.states[m.stateName][kg][key][ns] = newVal
34 return newVal, nil 39 return newVal, nil
35} 40}
@@ -37,8 +42,11 @@ func (m *memoryStateValue) Update(ctx context.Context, newVal any) (any, error)
37func (m *memoryStateValue) Clear(ctx context.Context) error { 42func (m *memoryStateValue) Clear(ctx context.Context) error {
38 kg := m.backend.currentGroupKey 43 kg := m.backend.currentGroupKey
39 key := m.backend.currentKey 44 key := m.backend.currentKey
40 if kgMap, exists := m.backend.states[m.stateName][kg]; exists { 45 ns := m.backend.currentNamespace
41 delete(kgMap, key) 46 if kgMap, ok := m.backend.states[m.stateName][kg]; ok {
47 if nsMap, ok := kgMap[key]; ok {
48 delete(nsMap, ns)
49 }
42 } 50 }
43 return nil 51 return nil
44} 52}