events – github.com/gobuffalo/events Index | Files | Directories

package events

import "github.com/gobuffalo/events"

Index

Constants

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"

Functions

func Emit

func Emit(e Event) error

Emit an event to all listeners

func EmitError

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

func EmitPayload

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

func List

func List() ([]string, error)

List all listeners

func LoadPlugins

func LoadPlugins() error

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

func SetManager

func SetManager(m Manager)

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

Types

type DeleteFn

type DeleteFn func()

func Listen

func Listen(l Listener) (DeleteFn, error)

Listen for events.

func NamedListen

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

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

func (e Event) IsError() bool

func (Event) MarshalJSON

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

MarshalJSON implements the json marshaler for an event

func (Event) String

func (e Event) String() string

func (Event) Validate

func (e Event) Validate() error

Validate that an event is ready to be emitted

type Listener

type Listener func(e Event)

Listener is a function capable of handling events

func Filter

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

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

Manager can be implemented to replace the default events manager

func DefaultManager

func DefaultManager() Manager

DefaultManager implements a map backed Manager

type Payload

type Payload = mapi.Mapi

Source Files

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

Directories

PathSynopsis
internal
Version
v1.4.3 (latest)
Published
Jul 6, 2022
Platform
linux/amd64
Imports
9 packages
Last checked
2 weeks ago

Tools for package owners.