-
Notifications
You must be signed in to change notification settings - Fork 5
/
example_test.go
47 lines (42 loc) · 981 Bytes
/
example_test.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
package simpleblob_test
import (
"context"
"fmt"
"github.com/PowerDNS/simpleblob"
"github.com/go-logr/logr"
// Register the memory backend plugin
_ "github.com/PowerDNS/simpleblob/backends/memory"
)
func Example() {
// Do not forget the:
// import _ "github.com/PowerDNS/simpleblob/backends/memory"
ctx := context.Background()
storage, err := simpleblob.GetBackend(
ctx,
"memory",
map[string]interface{}{
// add key-value options here
"foo": "example",
},
simpleblob.WithLogger(logr.Discard()), // replace with a real logger
)
check(err)
err = storage.Store(ctx, "example.txt", []byte("hello"))
check(err)
data, err := storage.Load(ctx, "example.txt")
check(err)
fmt.Println("data:", string(data))
list, err := storage.List(ctx, "")
check(err)
for _, entry := range list {
fmt.Println("list:", entry.Name, entry.Size)
}
// Output:
// data: hello
// list: example.txt 5
}
func check(err error) {
if err != nil {
panic(err)
}
}