From 7a7751b994f9bab8b73d5ea1e8beb297c6636b39 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Tue, 23 Feb 2016 17:59:19 -0800 Subject: [PATCH] etcdctlv3: combine Watch, WatchPrefix --- etcdctlv3/command/snapshot_command.go | 2 +- etcdctlv3/command/watch_command.go | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/etcdctlv3/command/snapshot_command.go b/etcdctlv3/command/snapshot_command.go index 4ea4446bb..3746630e3 100644 --- a/etcdctlv3/command/snapshot_command.go +++ b/etcdctlv3/command/snapshot_command.go @@ -54,7 +54,7 @@ func snapshotToStdout(c *clientv3.Client) { // must explicitly fetch first revision since no retry on stdout wapi := clientv3.NewWatcher(c) defer wapi.Close() - wr := <-wapi.WatchPrefix(context.TODO(), "", 1) + wr := <-wapi.Watch(context.TODO(), "", clientv3.WithPrefix(), clientv3.WithRev(1)) if len(wr.Events) > 0 { wr.CompactRevision = 1 } diff --git a/etcdctlv3/command/watch_command.go b/etcdctlv3/command/watch_command.go index 58defbefa..332345008 100644 --- a/etcdctlv3/command/watch_command.go +++ b/etcdctlv3/command/watch_command.go @@ -60,12 +60,11 @@ func watchCommandFunc(cmd *cobra.Command, args []string) { c := mustClientFromCmd(cmd) w := clientv3.NewWatcher(c) - var wc clientv3.WatchChan - if !watchPrefix { - wc = w.Watch(context.TODO(), args[0], watchRev) - } else { - wc = w.Watch(context.TODO(), args[0], watchRev) + opts := []clientv3.OpOption{clientv3.WithRev(watchRev)} + if watchPrefix { + opts = append(opts, clientv3.WithPrefix()) } + wc := w.Watch(context.TODO(), args[0], opts...) printWatchCh(wc) err := w.Close() if err == nil { @@ -114,12 +113,11 @@ func watchInteractiveFunc(cmd *cobra.Command, args []string) { if err != nil { key = moreargs[0] } - var ch clientv3.WatchChan + opts := []clientv3.OpOption{clientv3.WithRev(watchRev)} if watchPrefix { - ch = w.WatchPrefix(context.TODO(), key, watchRev) - } else { - ch = w.Watch(context.TODO(), key, watchRev) + opts = append(opts, clientv3.WithPrefix()) } + ch := w.Watch(context.TODO(), key, opts...) go printWatchCh(ch) } }