example_test.go 561 Bytes
Newer Older
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
1 2 3 4 5
package namespace_test

import (
	"fmt"

6 7
	ds "github.com/jbenet/go-datastore"
	nsds "github.com/jbenet/go-datastore/namespace"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
)

func Example() {
	mp := ds.NewMapDatastore()
	ns := nsds.Wrap(mp, ds.NewKey("/foo/bar"))

	k := ds.NewKey("/beep")
	v := "boop"

	ns.Put(k, v)
	fmt.Printf("ns.Put %s %s\n", k, v)

	v2, _ := ns.Get(k)
	fmt.Printf("ns.Get %s -> %s\n", k, v2)

	k3 := ds.NewKey("/foo/bar/beep")
	v3, _ := mp.Get(k3)
	fmt.Printf("mp.Get %s -> %s\n", k3, v3)
	// Output:
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
27
	// ns.Put /beep boop
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
28 29 30
	// ns.Get /beep -> boop
	// mp.Get /foo/bar/beep -> boop
}