From 01d1a579bc9df9905eb2754f8d2e68889678114c Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Tue, 14 Mar 2017 10:50:41 -0700 Subject: [PATCH] v3client: add example and godoc New --- etcdserver/api/v3client/doc.go | 29 +++++++++++++++++++++++++++++ etcdserver/api/v3client/v3client.go | 3 +++ 2 files changed, 32 insertions(+) diff --git a/etcdserver/api/v3client/doc.go b/etcdserver/api/v3client/doc.go index 8a8e15515..952643106 100644 --- a/etcdserver/api/v3client/doc.go +++ b/etcdserver/api/v3client/doc.go @@ -13,4 +13,33 @@ // limitations under the License. // Package v3client provides clientv3 interfaces from an etcdserver. +// +// Use v3client by creating an EtcdServer instance, then wrapping it with v3client.New: +// +// import ( +// "context" +// +// "github.com/coreos/etcd/embed" +// "github.com/coreos/etcd/etcdserver/api/v3client" +// ) +// +// ... +// +// // create an embedded EtcdServer from the default configuration +// cfg := embed.NewConfig() +// cfg.Dir = "default.etcd" +// e, err := embed.StartEtcd(cfg) +// if err != nil { +// // handle error! +// } +// +// // wrap the EtcdServer with v3client +// cli := v3client.New(e) +// +// // use like an ordinary clientv3 +// resp, err := cli.Put(context.TODO(), "some-key", "it works!") +// if err != nil { +// // handle error! +// } +// package v3client diff --git a/etcdserver/api/v3client/v3client.go b/etcdserver/api/v3client/v3client.go index 59d3e4a8d..027f7de32 100644 --- a/etcdserver/api/v3client/v3client.go +++ b/etcdserver/api/v3client/v3client.go @@ -24,6 +24,9 @@ import ( "github.com/coreos/etcd/proxy/grpcproxy/adapter" ) +// New creates a clientv3 client that wraps an in-process EtcdServer. Instead +// of making gRPC calls through sockets, the client makes direct function calls +// to the etcd server through its api/v3rpc function interfaces. func New(s *etcdserver.EtcdServer) *clientv3.Client { c := clientv3.NewCtxClient(context.Background())