Skip to content

Commit

Permalink
docs: add example in the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Sep 8, 2022
1 parent df4947e commit 4b87259
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
6 changes: 2 additions & 4 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@ import (
)

func main() {
addr := "localhost:8500"
ctx := context.Background()

// Initialize a new store.
config := &consul.Config{
ConnectionTimeout: 10 * time.Second,
}

kv, err := valkeyrie.NewStore(consul.StoreName, []string{addr}, config)
kv, err := valkeyrie.NewStore(ctx, consul.StoreName, []string{"localhost:8500"}, config)
if err != nil {
log.Fatal("Cannot create store consul")
}

key := "foo"
ctx := context.Background()

err = kv.Put(ctx, key, []byte("bar"), nil)
if err != nil {
Expand Down
50 changes: 48 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,52 @@ The benefit of `valkeyrie` is not to duplicate the code for programs that should

You can refer to [Examples](https://github.com/kvtools/valkeyrie/blob/master/docs/examples.md) for a basic overview of the library.

```go
package main

import (
"context"
"log"
"time"

"github.com/kvtools/consul"
"github.com/kvtools/valkeyrie"
)

func main() {
ctx := context.Background()

config := &consul.Config{
ConnectionTimeout: 10 * time.Second,
}

kv, err := valkeyrie.NewStore(ctx, consul.StoreName, []string{"localhost:8500"}, config)
if err != nil {
log.Fatal("Cannot create store consul")
}

key := "foo"


err = kv.Put(ctx, key, []byte("bar"), nil)
if err != nil {
log.Fatalf("Error trying to put value at key: %v", key)
}

pair, err := kv.Get(ctx, key, nil)
if err != nil {
log.Fatalf("Error trying accessing value at key: %v", key)
}

log.Printf("value: %s", string(pair.Value))

err = kv.Delete(ctx, key)
if err != nil {
log.Fatalf("Error trying to delete key %v", key)
}
}
```

## Compatibility

A **storage backend** in `valkeyrie` implements (fully or partially) the [Store](https://github.com/kvtools/valkeyrie/blob/master/store/store.go#L69) interface.
Expand Down Expand Up @@ -44,7 +90,7 @@ The store implementations:
- [redis](https://github.com/kvtools/redis)
- [zookeeper](https://github.com/kvtools/zookeeper)

The store tempate:
The store template:

- [template](https://github.com/kvtools/template)

Expand All @@ -66,4 +112,4 @@ The [Maintainers](https://github.com/kvtools/valkeyrie/blob/master/maintainers.m

Apache License Version 2.0

Valkeyrie is a hard fork of the unmaintained [libkv](https://github.com/docker/libkv).
Valkeyrie started as a hard fork of the unmaintained [libkv](https://github.com/docker/libkv).

0 comments on commit 4b87259

Please sign in to comment.