-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathstorage.go
43 lines (36 loc) · 993 Bytes
/
storage.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
package main
import (
"context"
"log"
)
func newDistributedStorage() *distributedStorage {
return &distributedStorage{
records: make(map[string][]byte),
}
}
type distributedStorage struct {
records map[string][]byte
}
func (d *distributedStorage) Get(_ context.Context, key string) ([]byte, bool) {
log.Printf("Getting key %s from the distributed storage\n", key)
value, ok := d.records[key]
return value, ok
}
func (d *distributedStorage) Set(_ context.Context, key string, value []byte) {
log.Printf("Writing key %s to the distributed storage\n", key)
d.records[key] = value
}
func (d *distributedStorage) GetBatch(_ context.Context, keys []string) map[string][]byte {
records := make(map[string][]byte)
for _, key := range keys {
if value, ok := d.records[key]; ok {
records[key] = value
}
}
return records
}
func (d *distributedStorage) SetBatch(_ context.Context, records map[string][]byte) {
for key, value := range records {
d.records[key] = value
}
}