doc: cleanup and improve for recently moved pkgs (#354)
* chore(atomicx): review docs and add usage example * chore(fsx): improve docs, return value, add examples * fix(kvstore): correct typo and add example * fix(multierror): add basic example * doc: revamp ooapi documentation
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package kvstore_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/kvstore"
|
||||
)
|
||||
|
||||
func ExampleMemory() {
|
||||
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
|
||||
}
|
||||
@@ -30,7 +30,7 @@ func (kvs *Memory) Get(key string) ([]byte, error) {
|
||||
return value, nil
|
||||
}
|
||||
|
||||
// Set sets a key into the key-value store
|
||||
// Set sets a key into the key-value store.
|
||||
func (kvs *Memory) Set(key string, value []byte) error {
|
||||
kvs.mu.Lock()
|
||||
defer kvs.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user