forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.go
38 lines (32 loc) · 825 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
package logical
import (
"bytes"
"encoding/json"
)
// Storage is the way that logical backends are able read/write data.
type Storage interface {
List(prefix string) ([]string, error)
Get(string) (*StorageEntry, error)
Put(*StorageEntry) error
Delete(string) error
}
// StorageEntry is the entry for an item in a Storage implementation.
type StorageEntry struct {
Key string
Value []byte
}
func (e *StorageEntry) DecodeJSON(out interface{}) error {
return json.Unmarshal(e.Value, out)
}
// StorageEntryJSON creates a StorageEntry with a JSON-encoded value.
func StorageEntryJSON(k string, v interface{}) (*StorageEntry, error) {
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
if err := enc.Encode(v); err != nil {
return nil, err
}
return &StorageEntry{
Key: k,
Value: buf.Bytes(),
}, nil
}