event

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package event provides the different Listeners

Index

Constants

View Source
const (
	Update = "UPDATE"
	Delete = "DELETE"
	Create = "CREATE"
)

Variables

View Source
var (
	ErrNilListener = errors.New("nil listener")
)

errors.

Functions

This section is empty.

Types

type Dispatcher

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

Dispatcher is the observer.

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher is a new Dispatcher for listeners.

func (*Dispatcher) DispatchEvent

func (dis *Dispatcher) DispatchEvent(event *Event) error

DispatchEvent sends the action trigger for a particular event on a configuration.

func (*Dispatcher) DispatchModuleEvent

func (dis *Dispatcher) DispatchModuleEvent(events []*Event) error

DispatchModuleEvent finds the registered function for callback according to the prefix of key in events.

func (*Dispatcher) RegisterListener

func (dis *Dispatcher) RegisterListener(listenerObj Listener, keys ...string) error

RegisterListener registers listener for particular configuration.

func (*Dispatcher) RegisterModuleListener

func (dis *Dispatcher) RegisterModuleListener(listenerObj ModuleListener, modulePrefixes ...string) error

RegisterModuleListener registers moduleListener for particular configuration.

func (*Dispatcher) UnRegisterListener

func (dis *Dispatcher) UnRegisterListener(listenerObj Listener, keys ...string) error

UnRegisterListener un-register listener for a particular configuration.

func (*Dispatcher) UnRegisterModuleListener

func (dis *Dispatcher) UnRegisterModuleListener(listenerObj ModuleListener, modulePrefixes ...string) error

UnRegisterModuleListener un-register moduleListener for a particular configuration.

type Event

type Event struct {
	EventSource string
	EventType   string
	Key         string
	Value       interface{}
	HasUpdated  bool
}

Event generated when any config changes.

func PopulateEvents

func PopulateEvents(sourceName string, currentConfig, updatedConfig map[string]interface{}) ([]*Event, error)

PopulateEvents compare old and new configurations to generate events that need to be updated.

type Listener

type Listener interface {
	Event(event *Event)
}

Listener All Listener should implement this Interface.

type ModuleListener

type ModuleListener interface {
	Event(event []*Event)
}

ModuleListener All moduleListener should implement this Interface.

type PrefixIndex

type PrefixIndex struct {
	Prefix    string
	NextParts map[string]*PrefixIndex
}

func (*PrefixIndex) AddPrefix

func (pre *PrefixIndex) AddPrefix(prefix string)

func (*PrefixIndex) FindPrefix

func (pre *PrefixIndex) FindPrefix(key string) string

func (*PrefixIndex) RemovePrefix

func (pre *PrefixIndex) RemovePrefix(prefix string)

Jump to

Keyboard shortcuts

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