-
Notifications
You must be signed in to change notification settings - Fork 1
/
dump.go
58 lines (46 loc) · 982 Bytes
/
dump.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
package main
import (
"encoding/json"
"fmt"
)
func dumpAllKeys(storage Storage) (errors []error) {
keys, err := storage.ListKey()
if err != nil {
return []error{err}
}
allKeys := []Key{}
for _, v := range keys {
value, err := storage.GetKey(v)
if err != nil {
errors = append(errors, err)
}
key := Key{}
err = json.Unmarshal([]byte(value), &key)
if err != nil {
errors = append(errors, err)
}
debugPrint(fmt.Sprintf("%#v", key))
allKeys = append(allKeys, key)
}
if len(errors) > 0 {
return errors
}
marshaledKeys, _ := json.Marshal(allKeys)
fmt.Println(string(marshaledKeys))
return nil
}
func dumpKey(storage Storage, name string) (err error) {
value, err := storage.GetKey(name)
if err != nil {
return err
}
key := Key{}
err = json.Unmarshal([]byte(value), &key)
if err != nil {
return err
}
debugPrint(fmt.Sprintf("%#v", key))
marshaledKey, _ := json.Marshal(key)
fmt.Println(string(marshaledKey))
return nil
}