forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage_inmem.go
53 lines (43 loc) · 947 Bytes
/
storage_inmem.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
package logical
import (
"sync"
"github.com/hashicorp/vault/physical"
)
// InmemStorage implements Storage and stores all data in memory.
type InmemStorage struct {
phys *physical.InmemBackend
once sync.Once
}
func (s *InmemStorage) List(prefix string) ([]string, error) {
s.once.Do(s.init)
return s.phys.List(prefix)
}
func (s *InmemStorage) Get(key string) (*StorageEntry, error) {
s.once.Do(s.init)
entry, err := s.phys.Get(key)
if err != nil {
return nil, err
}
if entry == nil {
return nil, nil
}
return &StorageEntry{
Key: entry.Key,
Value: entry.Value,
}, nil
}
func (s *InmemStorage) Put(entry *StorageEntry) error {
s.once.Do(s.init)
physEntry := &physical.Entry{
Key: entry.Key,
Value: entry.Value,
}
return s.phys.Put(physEntry)
}
func (s *InmemStorage) Delete(k string) error {
s.once.Do(s.init)
return s.phys.Delete(k)
}
func (s *InmemStorage) init() {
s.phys = physical.NewInmem(nil)
}