package state import ( "context" ) type memoryStateValue struct { backend *MemoryStateBackend stateName string } func (m *memoryStateValue) Value(ctx context.Context) (any, error) { kg := m.backend.currentGroupKey key := m.backend.currentKey ns := m.backend.currentNamespace if kgMap, ok := m.backend.states[m.stateName][kg][key]; ok { if v, hasKey := kgMap[ns]; hasKey { return v, nil } } return nil, nil } func (m *memoryStateValue) Update(ctx context.Context, newVal any) (any, error) { kg := m.backend.currentGroupKey key := m.backend.currentKey ns := m.backend.currentNamespace if _, ok := m.backend.states[m.stateName][kg]; !ok { m.backend.states[m.stateName][kg] = make(map[string]map[any]any) } if _, ok := m.backend.states[m.stateName][kg][key]; !ok { m.backend.states[m.stateName][kg][key] = make(map[any]any) } m.backend.states[m.stateName][kg][key][ns] = newVal return newVal, nil } func (m *memoryStateValue) Clear(ctx context.Context) error { kg := m.backend.currentGroupKey key := m.backend.currentKey ns := m.backend.currentNamespace if kgMap, ok := m.backend.states[m.stateName][kg]; ok { if nsMap, ok := kgMap[key]; ok { delete(nsMap, ns) } } return nil }