-
Notifications
You must be signed in to change notification settings - Fork 80
/
memory_store.go
50 lines (41 loc) · 926 Bytes
/
memory_store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package scenario
import (
"strings"
)
func NewMemoryStore() *MemoryStore {
status := make(map[string]string)
return &MemoryStore{status: status}
}
type MemoryStore struct {
status map[string]string
paused bool
}
func (sm *MemoryStore) Reset(name string) bool {
if _, f := sm.status[strings.ToLower(name)]; f {
sm.status[strings.ToLower(name)] = "not_started"
return true
}
return false
}
func (sm *MemoryStore) ResetAll() {
sm.status = make(map[string]string)
sm.paused = false
}
func (sm *MemoryStore) SetState(name, status string) {
if sm.paused {
return
}
sm.status[strings.ToLower(name)] = strings.ToLower(status)
}
func (sm *MemoryStore) GetState(name string) string {
if v, f := sm.status[strings.ToLower(name)]; f {
return v
}
return "not_started"
}
func (sm *MemoryStore) GetPaused() bool {
return sm.paused
}
func (sm *MemoryStore) SetPaused(newstate bool) {
sm.paused = newstate
}