events

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2020 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalEvents = RegisteredEvents{
	NginxPreStart:    &preStartEvent,
	NginxStart:       &startEvent,
	NginxWorkerStart: &startWorkerEvent,
	NginxExit:        &exitEvent,
	NginxWorkerExit:  &exitWorkerEvent,
	NginxPreReload:   &preReloadEvent,
	NginxReload:      &reloadEvent,
	ReloadStarted:    abool.NewBool(false),
}

GlobalEvents contains hardcoded NGINX events.

Functions

func Init

func Init()

Init creates the event channel and populates GlobalEvents instance.

Types

type Event

type Event struct {
	// Event name
	Name string
	// System of origin for event
	Origin string
	// Array of triggers to be invoked when event is broadcast
	OnTrigger []*Trigger
	// contains filtered or unexported fields
}

Event represents a unique wrapper event.

func (*Event) AddFinalTrigger

func (e *Event) AddFinalTrigger(trigger *Trigger)

AddFinalTrigger adds the penultimate (final) trigger to an event.

func (*Event) AddTrigger

func (e *Event) AddTrigger(trigger *Trigger)

AddTrigger adds a trigger to an Event.

func (*Event) ID

func (e *Event) ID() string

ID returns a unique ID for the event based on the Origin and Name.

func (*Event) String

func (e *Event) String() string

func (*Event) Trigger

func (e *Event) Trigger(metadata map[string]interface{}) []error

Trigger runs a closure associated with event and broadcasts message to event channel.

type Message

type Message struct {
	Event    Event
	Metadata map[string]interface{}
}

Message is used when notifying that an event occurred.

type NginxLogParseError

type NginxLogParseError struct {
	Message string
	LogLine string
	Err     error
}

NginxLogParseError is thrown when there is a problem parsing a NGINX log line.

func (*NginxLogParseError) Cause

func (e *NginxLogParseError) Cause() error

Cause returns the cause of the error - the same as the Unwrap() method.

func (*NginxLogParseError) Error

func (e *NginxLogParseError) Error() string

func (*NginxLogParseError) Unwrap

func (e *NginxLogParseError) Unwrap() error

type RegisteredEvents

type RegisteredEvents struct {
	NginxPreStart    *Event
	NginxStart       *Event
	NginxWorkerStart *Event
	NginxExit        *Event
	NginxWorkerExit  *Event
	NginxPreReload   *Event
	NginxReload      *Event

	ReloadStarted *abool.AtomicBool
	// contains filtered or unexported fields
}

RegisteredEvents provides global access to events and flags.

func (*RegisteredEvents) AddTriggerByEventName

func (re *RegisteredEvents) AddTriggerByEventName(eventName string, trigger *Trigger) error

AddTriggerByEventName allows for adding a reference to a trigger that is to be associated with an event (as indicated by name).

func (*RegisteredEvents) AddTriggerToAllEvents

func (re *RegisteredEvents) AddTriggerToAllEvents(trigger Trigger)

AddTriggerToAllEvents adds a trigger to all events listed in RegisteredEvents.

func (*RegisteredEvents) EventNames

func (re *RegisteredEvents) EventNames() []string

EventNames returns the names of the available nginx events.

func (*RegisteredEvents) FindEventByName

func (re *RegisteredEvents) FindEventByName(eventName string) *Event

FindEventByName allows for looking up an event object by its name.

func (*RegisteredEvents) ParseForTriggerableEvent

func (re *RegisteredEvents) ParseForTriggerableEvent(line string)

ParseForTriggerableEvent parses a NGINX log line for matching text that is associated with an event type. If an associated event type is found, then the Trigger() method of that event will be invoked.

Note: This method is stateful in that it behaves differently depending on what previous lines were received. Unfortunately, this is a needed complexity due to the way NGINX logs.

type Trigger

type Trigger struct {
	Name     string
	Function func(message Message) error
}

Trigger function to execute when an event has OnTrigger() invoked.

func (*Trigger) String

func (t *Trigger) String() string

Jump to

Keyboard shortcuts

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