watch.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2016 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package clientv3
  15. import (
  16. "github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
  17. pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
  18. storagepb "github.com/coreos/etcd/storage/storagepb"
  19. )
  20. type Watcher interface {
  21. // Watch watches on a single key. The watched events will be returned
  22. // through the returned channel.
  23. // If the watch is slow or the required rev is compacted, the watch request
  24. // might be canceled from the server-side and the chan will be closed.
  25. Watch(cxt context.Context, key string, rev int64) <-chan WatchResponse
  26. // Watch watches on a prefix. The watched events will be returned
  27. // through the returned channel.
  28. // If the watch is slow or the required rev is compacted, the watch request
  29. // might be canceled from the server-side and the chan will be closed.
  30. WatchPrefix(cxt context.Context, prefix string, rev int64) <-chan WatchResponse
  31. // Close closes the watcher and cancels all watch requests.
  32. Close() error
  33. }
  34. type WatchResponse struct {
  35. Header pb.ResponseHeader
  36. Events []*storagepb.Event
  37. }