notifiers

package
v2.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventTypeStrings

func EventTypeStrings() []string

EventTypeStrings returns a slice of all String values of the enum

func NewFxDriver

func NewFxDriver(
	statusRegistry status.Registry,
	prometheusRegistry *prometheus.Registry,
	getUnmarshallerFunc GetUnmarshallerFunc,
	fxOptionsFuncs []FxOptionsFunc,
) (*fxDriver, error)

NewFxDriver creates a new FxDriver.

func NewKeyBase

func NewKeyBase(key Key) *keyBase

NewKeyBase creates a new key notifier.

func NewPrefixBase

func NewPrefixBase(prefix string) *prefixBase

NewPrefixBase creates a new prefix notifier.

func NewUnmarshalKeyNotifier

func NewUnmarshalKeyNotifier(key Key,
	unmarshaller config.Unmarshaller,
	unmarshalNotifyFunc UnmarshalNotifyFunc,
) (*unmarshalKeyNotifier, error)

NewUnmarshalKeyNotifier creates a new instance of ConfigKeyNotifier.

func NewUnmarshalPrefixNotifier

func NewUnmarshalPrefixNotifier(prefix string,
	unmarshalNotifyFunc UnmarshalNotifyFunc,
	getUnmarshallerFunc GetUnmarshallerFunc,
) (*unmarshalPrefixNotifier, error)

NewUnmarshalPrefixNotifier returns a new instance of UnmarshalPrefixNotifier.

func NotifierLifecycle

func NotifierLifecycle(lc fx.Lifecycle, watcher Watcher, notifier PrefixNotifier)

NotifierLifecycle adds/removed prefix notifier to etcd watcher.

func WatcherLifecycle

func WatcherLifecycle(lc fx.Lifecycle, watcher Watcher, notifiers []PrefixNotifier)

WatcherLifecycle starts/stops watcher and adds/removes prefix notifier(s) to etcd watcher.

Types

type BasicKeyNotifier

type BasicKeyNotifier struct {
	NotifyFunc NotifyFunc
	KeyBase
}

BasicKeyNotifier holds fields for basic key notifier.

func NewBasicKeyNotifier

func NewBasicKeyNotifier(key Key, notifyFunc NotifyFunc) *BasicKeyNotifier

NewBasicKeyNotifier returns a new basic key notifier.

func (*BasicKeyNotifier) Notify

func (bfn *BasicKeyNotifier) Notify(event Event)

Notify calls the registered notifier function with the given event.

type DefaultTrackers

type DefaultTrackers struct {
	// contains filtered or unexported fields
}

DefaultTrackers is a collection of key trackers.

func NewDefaultTrackers

func NewDefaultTrackers() *DefaultTrackers

NewDefaultTrackers creates a new instance of Trackers.

func (*DefaultTrackers) AddKeyNotifier

func (t *DefaultTrackers) AddKeyNotifier(notifier KeyNotifier) error

AddKeyNotifier is a convenience function to add a key notifier to the underlying trackers. If the key of the given notifier is already tracked, the notifier will be added to the existing tracker.

func (*DefaultTrackers) AddPrefixNotifier

func (t *DefaultTrackers) AddPrefixNotifier(notifier PrefixNotifier) error

AddPrefixNotifier is a convenience function to add a prefix notifier to the underlying trackers. Internally, a key notifier is added for each key under the given prefix. If the prefix of the given notifier is already tracked, the notifier will be added to the existing tracker.

func (*DefaultTrackers) Purge

func (t *DefaultTrackers) Purge(prefix string)

Purge is a convenience function to purge all trackers. This will remove all key notifiers and prefix notifiers.

func (*DefaultTrackers) RemoveEvent

func (t *DefaultTrackers) RemoveEvent(key Key)

RemoveEvent sends a Remove event with the given key and value to the underlying event channel.

func (*DefaultTrackers) RemoveKeyNotifier

func (t *DefaultTrackers) RemoveKeyNotifier(notifier KeyNotifier) error

RemoveKeyNotifier is a convenience function to remove a key notifier from the underlying trackers. If the key of the given notifier is not tracked, the notifier will be ignored.

func (*DefaultTrackers) RemovePrefixNotifier

func (t *DefaultTrackers) RemovePrefixNotifier(notifier PrefixNotifier) error

RemovePrefixNotifier is a convenience function to remove a prefix notifier from the underlying trackers. Internally, a key notifier is removed for each key under the given prefix. If the prefix of the given notifier is not tracked, the notifier will be ignored.

func (*DefaultTrackers) Start

func (t *DefaultTrackers) Start() error

Start opens the underlying event channel and starts the event loop. See AddKeyNotifier, AddPrefixNotifier, RemoveKeyNotifier, RemovePrefixNotifier, and Purge for more information.

func (*DefaultTrackers) Stop

func (t *DefaultTrackers) Stop() error

Stop closes all channels and waits for the goroutine to finish.

func (*DefaultTrackers) UpdateValue

func (t *DefaultTrackers) UpdateValue(key Key, updateFunc UpdateValueFunc)

UpdateValue returns the current value tracked by a key.

func (*DefaultTrackers) WriteEvent

func (t *DefaultTrackers) WriteEvent(key Key, value []byte)

WriteEvent sends a Write event with the given key and value to the underlying event channel.

type Event

type Event struct {
	Key
	Value []byte
	Type  EventType
}

Event is the event that is passed to the notifier.

func (Event) String

func (event Event) String() string

String returns the string representation of the event.

type EventType

type EventType uint8

EventType is the type of event.

const (
	// Write represents that the watched entity has been written to.
	// In case of a file, it could have been created, modified, or symlinked.
	// In case of an etcd entry, it could have been added or updated.
	Write EventType = 1 << iota
	// Remove represents that the watched entity has been removed.
	Remove
)

func EventTypeString

func EventTypeString(s string) (EventType, error)

EventTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func EventTypeValues

func EventTypeValues() []EventType

EventTypeValues returns all values of the enum

func (EventType) IsAEventType

func (i EventType) IsAEventType() bool

IsAEventType returns "true" if the value is listed in the enum definition. "false" otherwise

func (EventType) String

func (i EventType) String() string

type EventWriter

type EventWriter interface {
	WriteEvent(key Key, value []byte)
	RemoveEvent(key Key)
	Purge(prefix string)
	UpdateValue(key Key, updateFunc UpdateValueFunc)
}

EventWriter can be used to inject events into a tracker collection.

func NewPrefixedEventWriter

func NewPrefixedEventWriter(prefix string, ew EventWriter) EventWriter

NewPrefixedEventWriter returns an event writer which keys will be automatically prefixed with given prefix.

It's recommended that prefix ends up some kind of delimiter, like `.` or `/`.

type FxOptionsFunc

type FxOptionsFunc func(Key, config.Unmarshaller, status.Registry) (fx.Option, error)

FxOptionsFunc is a function that returns fx.Option.

type GetUnmarshallerFunc

type GetUnmarshallerFunc func(bytes []byte) (config.Unmarshaller, error)

GetUnmarshallerFunc is a function that is called to create a new unmarshaller.

type Key

type Key string

Key is the key that is used to identify the notifier.

func (Key) String

func (key Key) String() string

String returns the string representation of the notifier.

type KeyBase

type KeyBase interface {
	GetKey() Key
	// contains filtered or unexported methods
}

KeyBase is interface for key.

type KeyNotifier

type KeyNotifier interface {
	KeyBase
	Notify(Event)
}

KeyNotifier is the interface that all key notifiers must implement.

type NotifyFunc

type NotifyFunc func(Event)

NotifyFunc is a signature for basic notifier function.

type PrefixBase

type PrefixBase interface {
	GetPrefix() string
	// contains filtered or unexported methods
}

PrefixBase is the base type for all prefix notifiers.

type PrefixNotifier

type PrefixNotifier interface {
	PrefixBase
	GetKeyNotifier(key Key) (KeyNotifier, error)
}

PrefixNotifier is the interface that all prefix notifiers must implement.

func NewBasicPrefixNotifier

func NewBasicPrefixNotifier(prefix string, notifyFunc NotifyFunc) PrefixNotifier

NewBasicPrefixNotifier returns a new basic prefix notifier.

type Trackers

type Trackers interface {
	Watcher
	EventWriter
}

Trackers is the interface of a tracker collection.

type TrackersConstructor

type TrackersConstructor struct {
	Name string
}

TrackersConstructor is a Fx constructor for Trackers.

func (TrackersConstructor) Annotate

func (t TrackersConstructor) Annotate() fx.Option

Annotate provides Fx annotated Tracker.

type TransformFunc

type TransformFunc func(key Key, bytes []byte, etype EventType) (Key, []byte, error)

TransformFunc is the callback signature that other notifiers (like NewPrefixToEtcdNotifier and NewKeyToEtcdNotifier) can use to receive notification before contents are processed. This function can transform the key and contents before processing them further.

type UnmarshalNotifyFunc

type UnmarshalNotifyFunc func(Event, config.Unmarshaller)

UnmarshalNotifyFunc is a function that is called when a config key is written.

type UpdateValueFunc

type UpdateValueFunc func(oldValue []byte) (EventType, []byte)

UpdateValueFunc is a function that can be used to update the value of an existing tracker entry.

type Watcher

type Watcher interface {
	AddPrefixNotifier(PrefixNotifier) error
	RemovePrefixNotifier(PrefixNotifier) error
	AddKeyNotifier(KeyNotifier) error
	RemoveKeyNotifier(KeyNotifier) error
	Start() error
	Stop() error
}

Watcher is a generic interface for watchers/trackers.

Jump to

Keyboard shortcuts

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