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 if kgMap, exist := m.backend.states[m.stateName][kg]; exist { if v, hasKey := kgMap[key]; 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 if _, exists := m.backend.states[m.stateName][kg]; !exists { m.backend.states[m.stateName][kg] = make(map[string]any) } m.backend.states[m.stateName][kg][key] = newVal return newVal, nil } func (m *memoryStateValue) Clear(ctx context.Context) error { kg := m.backend.currentGroupKey key := m.backend.currentKey if kgMap, exists := m.backend.states[m.stateName][kg]; exists { delete(kgMap, key) } return nil }