-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
43 lines (36 loc) · 964 Bytes
/
api.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 (
"github.com/sjsafranek/DiffStore"
)
// Get gets value by key and bucket. Decrypts value using passphrase.
func Get(namespace, key, passphrase string) (diffstore.DiffStore, error) {
var ddata diffstore.DiffStore
data, err := DB.Get(namespace, key, passphrase)
if nil != err {
return ddata, err
}
ddata.Decode([]byte(data))
return ddata, err
}
// Set sets value by key and bucket. Encrypts value using passphrase.
func Set(namespace, key, value, passphrase string) error {
ddata, err := Get(namespace, key, passphrase)
if nil != err {
if err.Error() == "Not found" {
// create new diffstore if key not found in database
ddata = diffstore.New()
} else {
return err
}
}
ddata.Update(value)
enc, err := ddata.Encode()
if nil != err {
return err
}
return DB.Set(namespace, key, string(enc), passphrase)
}
//
// func Remove(key, passphrase string) error {
// return DB.Remove("store", key, passphrase)
// }