events: Index | Files | Directories

package events

import ""


Package Files

event.go events.go filter.go listener.go listener_map.go manager.go plugins.go version.go


const (
    // ErrGeneral is emitted for general errors
    ErrGeneral = "general:err"
    // ErrPanic is emitted when a panic is recovered
    ErrPanic = "panic:err"
const Version = "v1.4.0"

func Emit Uses

func Emit(e Event) error

Emit an event to all listeners

func EmitError Uses

func EmitError(kind string, err error, payload interface{}) error

func EmitPayload Uses

func EmitPayload(kind string, payload interface{}) error

func List Uses

func List() ([]string, error)

List all listeners

func LoadPlugins Uses

func LoadPlugins() error

LoadPlugins will add listeners for any plugins that support "events"

func SetManager Uses

func SetManager(m Manager)

SetManager allows you to replace the default event manager with a custom one

type DeleteFn Uses

type DeleteFn func()

func Listen Uses

func Listen(l Listener) (DeleteFn, error)

Listen for events.

func NamedListen Uses

func NamedListen(name string, l Listener) (DeleteFn, error)

NamedListen for events. Name is the name of the listener NOT the events you want to listen for, so something like "my-listener", "kafka-listener", etc...

type Event Uses

type Event struct {
    // Kind is the "type" of event "app:start"
    Kind string `json:"kind"`
    // Message is optional
    Message string `json:"message"`
    // Payload is optional
    Payload Payload `json:"payload"`
    // Error is optional
    Error error `json:"-"`

Event represents different events in the lifecycle of a Buffalo app

func (Event) IsError Uses

func (e Event) IsError() bool

func (Event) MarshalJSON Uses

func (e Event) MarshalJSON() ([]byte, error)

MarshalJSON implements the json marshaler for an event

func (Event) String Uses

func (e Event) String() string

func (Event) Validate Uses

func (e Event) Validate() error

Validate that an event is ready to be emitted

type Listener Uses

type Listener func(e Event)

Listener is a function capable of handling events

func Filter Uses

func Filter(s string, fn Listener) Listener

Filter compiles the string as a regex and returns the original listener wrapped in a new listener that filters incoming events by the Kind

type Manager Uses

type Manager interface {
    Listen(string, Listener) (DeleteFn, error)
    Emit(Event) error

Manager can be implemented to replace the default events manager

func DefaultManager Uses

func DefaultManager() Manager

DefaultManager implements a map backed Manager

type Payload Uses

type Payload = mapi.Mapi



Package events imports 9 packages (graph) and is imported by 20 packages. Updated 2019-06-23. Refresh now. Tools for package owners.