forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
51 lines (44 loc) · 1.05 KB
/
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
48
49
50
51
package influxdb_test
import (
"context"
"fmt"
"time"
platform "github.com/influxdata/influxdb"
"github.com/influxdata/influxdb/bolt"
)
func ExampleKeyValueLog() {
c := bolt.NewClient()
c.Path = "example.bolt"
ctx := context.Background()
if err := c.Open(ctx); err != nil {
panic(err)
}
for i := 0; i < 10; i++ {
if err := c.AddLogEntry(ctx, []byte("bucket_0_auditlog"), []byte(fmt.Sprintf("abc-%v", i)), time.Now()); err != nil {
panic(err)
}
}
opts := platform.FindOptions{Limit: 2, Offset: 1, Descending: false}
if err := c.ForEachLogEntry(ctx, []byte("bucket_0_auditlog"), opts, func(v []byte, t time.Time) error {
fmt.Println(t.UTC())
fmt.Println(string(v))
fmt.Println()
return nil
}); err != nil {
panic(err)
}
v, t, err := c.LastLogEntry(ctx, []byte("bucket_0_auditlog"))
if err != nil {
panic(err)
}
fmt.Println(t.UTC())
fmt.Println(string(v))
fmt.Println()
v, t, err = c.FirstLogEntry(ctx, []byte("bucket_0_auditlog"))
if err != nil {
panic(err)
}
fmt.Println(t.UTC())
fmt.Println(string(v))
fmt.Println()
}