Documentation
¶
Overview ¶
Package kvstore implements model.KeyValueStore.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNoSuchKey = errors.New("no such key")
ErrNoSuchKey indicates that there's no value for the given key.
Functions ¶
This section is empty.
Types ¶
type FS ¶
type FS struct {
// contains filtered or unexported fields
}
FS is a file-system based KVStore.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is an in-memory key-value store.
The zero value is ready to use.
Example ¶
package main
import (
"errors"
"fmt"
"log"
"reflect"
"github.com/ooni/probe-engine/pkg/kvstore"
)
func main() {
kvs := &kvstore.Memory{}
if _, err := kvs.Get("akey"); !errors.Is(err, kvstore.ErrNoSuchKey) {
log.Fatal("unexpected error", err)
}
val := []byte("value")
if err := kvs.Set("akey", val); err != nil {
log.Fatal("unexpected error", err)
}
out, err := kvs.Get("akey")
if err != nil {
log.Fatal("unexpected error", err)
}
fmt.Printf("%+v\n", reflect.DeepEqual(val, out))
}
Output: true
Click to show internal directories.
Click to hide internal directories.