watch

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package watch implements better watch semantics on top of etcd. See this issue for the reasoning behind the package: https://github.com/coreos/etcd/issues/7362

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckType

func CheckType(template proto.Message, val interface{}) error

CheckType checks to make sure val has the same type as template, unless template is nil in which case it always returns nil.

Types

type Event

type Event struct {
	Key      []byte
	Value    []byte
	Type     EventType
	Rev      int64
	Ver      int64
	Err      error
	Template proto.Message
}

Event is an event that occurred to an item in etcd.

func (*Event) Unmarshal

func (e *Event) Unmarshal(key *string, val proto.Message) error

Unmarshal unmarshals the item in an event into a protobuf message.

type EventType

type EventType int

EventType is the type of event

const (
	// EventPut happens when an item is added
	EventPut EventType = iota
	// EventDelete happens when an item is removed
	EventDelete
	// EventError happens when an error occurred
	EventError
)

type Option

type Option func(WatchOptions) WatchOptions

Option is a function that modifies the set of options to use when watching

func WithSort

func WithSort(sortTarget etcd.SortTarget, sortOrder etcd.SortOrder) Option

WithSort specifies the sort to use for the watcher

type WatchOptions

type WatchOptions struct {
	SortTarget    etcd.SortTarget
	SortOrder     etcd.SortOrder
	IncludePut    bool
	IncludeDelete bool
}

WatchOptions is a set of options that can be used when watching

func DefaultWatchOptions

func DefaultWatchOptions() WatchOptions

func IgnoreDelete

func IgnoreDelete(opt WatchOptions) WatchOptions

IgnoreDelete discards DELETE events from the watcher

func IgnorePut

func IgnorePut(opt WatchOptions) WatchOptions

IgnorePut discards PUT events from the watcher

func SumOptions

func SumOptions(opts ...Option) WatchOptions

type Watcher

type Watcher interface {
	// Watch returns a channel that delivers events
	Watch() <-chan *Event
	// Close this channel when you are done receiving events
	Close()
}

Watcher ...

func MakeEtcdWatcher

func MakeEtcdWatcher(eventCh chan *Event, done chan struct{}) Watcher

MakeEtcdWatcher returns a Watcher that uses the given event channel and done channel internally to deliver events and signal closure, respectively.

func NewEtcdWatcher

func NewEtcdWatcher(ctx context.Context, client *etcd.Client, trimPrefix, prefix string, template proto.Message, opts ...Option) (Watcher, error)

NewEtcdWatcher watches a given etcd prefix for events.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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