-
Notifications
You must be signed in to change notification settings - Fork 17
/
stores.go
61 lines (47 loc) · 1.13 KB
/
stores.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
51
52
53
54
55
56
57
58
59
60
61
package betwixt
type Store interface {
Init()
Close()
GetClient(string) RegisteredClient
GetClients() map[string]RegisteredClient
PutClient(id string, c RegisteredClient)
DeleteClient(id string)
UpdateTS(id string)
}
func NewInMemoryStore() *InMemoryStore {
return &InMemoryStore{
connectedClients: make(map[string]RegisteredClient),
}
}
type InMemoryStore struct {
connectedClients map[string]RegisteredClient
}
func (db *InMemoryStore) Init() {
}
func (db *InMemoryStore) Close() {
}
func (db *InMemoryStore) GetClient(name string) RegisteredClient {
return db.connectedClients[name]
}
func (db *InMemoryStore) GetClients() map[string]RegisteredClient {
return db.connectedClients
}
func (db *InMemoryStore) PutClient(name string, c RegisteredClient) {
db.connectedClients[name] = c
}
func (db *InMemoryStore) DeleteClient(name string) {
for k, v := range db.connectedClients {
if v.GetId() == name {
delete(db.connectedClients, k)
return
}
}
}
func (db *InMemoryStore) UpdateTS(name string) {
for k, v := range db.connectedClients {
if v.GetId() == name {
v.Update()
db.connectedClients[k] = v
}
}
}