forked from apilayer/goiban-data
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathin_memory_store.go
More file actions
42 lines (32 loc) · 738 Bytes
/
Copy pathin_memory_store.go
File metadata and controls
42 lines (32 loc) · 738 Bytes
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
package data
type Query struct {
Country string
BankCode string
}
type InMemoryStore struct {
records map[Query]*BankInfo
}
func NewInMemoryStore() *InMemoryStore {
return &InMemoryStore{
records: make(map[Query]*BankInfo),
}
}
func (s *InMemoryStore) Find(country string, bankCode string) (*BankInfo, error) {
key := Query{country, bankCode}
return s.records[key], nil
}
func (s *InMemoryStore) Store(data BankInfo) (bool, error) {
key := Query{data.Country, data.Bankcode}
s.records[key] = &data
return true, nil
}
func (s *InMemoryStore) Clear(source string) (int, error) {
deleted := 0
for k, v := range s.records {
if v.Source == source {
delete(s.records, k)
deleted++
}
}
return deleted, nil
}