-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathkv_v1.go
96 lines (80 loc) · 1.36 KB
/
kv_v1.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package vault
const (
pathPrefix string = "v1"
)
type KVv1 struct {
Service
}
func (c *Client) KVv1() *KVv1 {
return c.KVv1WithMountPoint("kv")
}
func (c *Client) KVv1WithMountPoint(mountPoint string) *KVv1 {
return &KVv1{
Service: Service{
client: c,
MountPoint: mountPoint,
},
}
}
func (k *KVv1) Create(id string, data map[string]string) error {
err := k.client.Write(
[]string{
pathPrefix,
k.MountPoint,
id,
}, data, nil, nil,
)
if err != nil {
return err
}
return nil
}
type KVv1ReadResponse struct {
Data map[string]string `json:"data"`
}
func (k *KVv1) Read(key string) (*KVv1ReadResponse, error) {
readRes := &KVv1ReadResponse{}
err := k.client.Read(
[]string{
pathPrefix,
k.MountPoint,
key,
}, readRes, nil,
)
if err != nil {
return nil, err
}
return readRes, nil
}
type KVv1ListResponse struct {
Data struct {
Keys []string `json:"keys"`
} `json:"data"`
}
func (k *KVv1) List(key string) (*KVv1ListResponse, error) {
listRes := &KVv1ListResponse{}
err := k.client.List(
[]string{
pathPrefix,
k.MountPoint,
key,
}, nil, listRes, nil,
)
if err != nil {
return nil, err
}
return listRes, nil
}
func (k *KVv1) Delete(key string) error {
err := k.client.Delete(
[]string{
pathPrefix,
k.MountPoint,
key,
}, nil, nil, nil,
)
if err != nil {
return err
}
return nil
}