notifiers

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: AGPL-3.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 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
	KeyNotifierBase
}

BasicKeyNotifier holds fields for basic key notifier.

func (*BasicKeyNotifier) Notify

func (bfn *BasicKeyNotifier) Notify(event Event)

Notify calls the registered notifier function with the given event.

type BasicPrefixNotifier

type BasicPrefixNotifier struct {
	NotifyFunc NotifyFunc
	PrefixNotifierBase
}

BasicPrefixNotifier holds fields for basic prefix notifier.

func (*BasicPrefixNotifier) GetKeyNotifier

func (bdn *BasicPrefixNotifier) GetKeyNotifier(key Key) KeyNotifier

GetKeyNotifier returns a basic key notifier for the given key.

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) GetCurrentValue

func (t *DefaultTrackers) GetCurrentValue(key Key) []byte

GetCurrentValue returns the current value tracked by a key.

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) 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 FxDriver

type FxDriver struct {
	// Options for new unmarshaller instances
	UnmarshalPrefixNotifier

	// function to provide fx.Options.
	//
	// Resulting fx.Options will be used to create a "mini FX-based apps" per key.
	// The lifecycle of the app will be tied to the existence of the key.
	// Note that when key's contents change the previous App will be stopped
	// and a fresh one will be created.
	FxOptionsFuncs     []FxOptionsFunc
	StatusRegistry     status.Registry
	PrometheusRegistry *prometheus.Registry
}

FxDriver tracks prefix and allows spawning "mini FX-based apps" per key in the prefix.

func (*FxDriver) GetKeyNotifier

func (fxDriver *FxDriver) GetKeyNotifier(key Key) KeyNotifier

GetKeyNotifier returns a KeyNotifier that will notify the driver of key changes.

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 KeyNotifier

type KeyNotifier interface {
	GetKey() Key
	SetKey(Key)
	Notify(Event)
	// contains filtered or unexported methods
}

KeyNotifier is the interface that all key notifiers must implement.

type KeyNotifierBase

type KeyNotifierBase struct {
	NotifierBase
	// contains filtered or unexported fields
}

KeyNotifierBase is the base type for all key notifiers.

func (*KeyNotifierBase) GetKey

func (knb *KeyNotifierBase) GetKey() Key

GetKey returns the key.

func (*KeyNotifierBase) SetKey

func (knb *KeyNotifierBase) SetKey(key Key)

SetKey sets the key.

type NotifierBase

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

NotifierBase is the base type for all notifiers.

func (*NotifierBase) GetTransformFunc

func (idb *NotifierBase) GetTransformFunc() TransformFunc

GetTransformFunc returns the transform function.

func (*NotifierBase) SetTransformFunc

func (idb *NotifierBase) SetTransformFunc(tf TransformFunc)

SetTransformFunc sets the transform function.

type NotifyFunc

type NotifyFunc func(Event)

NotifyFunc is a signature for basic notifier function.

type PrefixNotifier

type PrefixNotifier interface {
	GetPrefix() string
	GetKeyNotifier(key Key) KeyNotifier
	// contains filtered or unexported methods
}

PrefixNotifier is the interface that all prefix notifiers must implement.

type PrefixNotifierBase

type PrefixNotifierBase struct {
	NotifierBase
	Prefix string
}

PrefixNotifierBase is the base type for all prefix notifiers.

func (*PrefixNotifierBase) GetPrefix

func (pnb *PrefixNotifierBase) GetPrefix() string

GetPrefix returns the prefix.

type Trackers

type Trackers interface {
	Watcher
	WriteEvent(key Key, value []byte)
	RemoveEvent(key Key)
	GetCurrentValue(key Key) []byte
	Purge(prefix string)
}

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 UnmarshalKeyNotifier

type UnmarshalKeyNotifier struct {
	Unmarshaller config.Unmarshaller

	UnmarshalNotifyFunc UnmarshalNotifyFunc
	KeyNotifierBase
	// contains filtered or unexported fields
}

UnmarshalKeyNotifier holds the state of a key notifier that updates config at a key using the provided unmarshaller.

func NewUnmarshalKeyNotifier

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

NewUnmarshalKeyNotifier creates a new instance of ConfigKeyNotifier.

func (*UnmarshalKeyNotifier) Notify

func (cfn *UnmarshalKeyNotifier) Notify(event Event)

Notify provides an unmarshaller based on received event. It reloads the the bytes into unmarshaller before invoking callback.

type UnmarshalNotifyFunc

type UnmarshalNotifyFunc func(Event, config.Unmarshaller)

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

type UnmarshalPrefixNotifier

type UnmarshalPrefixNotifier struct {
	UnmarshalNotifyFunc UnmarshalNotifyFunc
	GetUnmarshallerFunc GetUnmarshallerFunc
	PrefixNotifierBase
}

UnmarshalPrefixNotifier holds the state of a prefix notifier that updates config at a prefix using the provided unmarshaller.

func (*UnmarshalPrefixNotifier) GetKeyNotifier

func (cdn *UnmarshalPrefixNotifier) GetKeyNotifier(key Key) KeyNotifier

GetKeyNotifier returns a new key notifier for the given key.

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