namespace

package
v3.3.24+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package namespace is a clientv3 wrapper that translates all keys to begin with a given prefix.

First, create a client:

cli, err := clientv3.New(clientv3.Config{Endpoints: []string{"localhost:2379"}})
if err != nil {
	// handle error!
}

Next, override the client interfaces:

unprefixedKV := cli.KV
cli.KV = namespace.NewKV(cli.KV, "my-prefix/")
cli.Watcher = namespace.NewWatcher(cli.Watcher, "my-prefix/")
cli.Lease = namespace.NewLease(cli.Lease, "my-prefix/")

Now calls using 'cli' will namespace / prefix all keys with "my-prefix/":

cli.Put(context.TODO(), "abc", "123")
resp, _ := unprefixedKV.Get(context.TODO(), "my-prefix/abc")
fmt.Printf("%s\n", resp.Kvs[0].Value)
// Output: 123
unprefixedKV.Put(context.TODO(), "my-prefix/abc", "456")
resp, _ = cli.Get("abc")
fmt.Printf("%s\n", resp.Kvs[0].Value)
// Output: 456

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewKV

func NewKV(kv clientv3.KV, prefix string) clientv3.KV

NewKV wraps a KV instance so that all requests are prefixed with a given string.

func NewLease

func NewLease(l clientv3.Lease, prefix string) clientv3.Lease

NewLease wraps a Lease interface to filter for only keys with a prefix and remove that prefix when fetching attached keys through TimeToLive.

func NewWatcher

func NewWatcher(w clientv3.Watcher, prefix string) clientv3.Watcher

NewWatcher wraps a Watcher instance so that all Watch requests are prefixed with a given string and all Watch responses have the prefix removed.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL