events

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: MIT Imports: 11 Imported by: 0

README

-events-go

-events-go is part of the kiss-my-package set used by apps like FaceMasq, PaperBag, Celestial, Executrix, and more

Documentation

Index

Constants

View Source
const (
	// ErrGeneral is emitted for general errors.
	ErrGeneral = "general:err"
	// ErrPanic is emitted when a panic is recovered.
	ErrPanic = "panic:err"
)

Variables

This section is empty.

Functions

func Emit

func Emit(ctx context.Context, e Event) error

Emit an event to all listeners.

func EmitError

func EmitError(ctx context.Context, kind string, err error, payload interface{}) error

func EmitPayload

func EmitPayload(ctx context.Context, kind string, payload interface{}) error

func List

func List() ([]string, error)

List all listeners.

func SetManager

func SetManager(custom 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(ctx context.Context, e Event) error

Listener is a function capable of handling events.

func Filter

func Filter(ctx context.Context, match string, original Listener) Listener

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

type Manager

type Manager interface {
	Listen(string, Listener) (DeleteFn, error)
	Emit(context.Context, Event) error
	List() ([]string, error)
	Listeners() *listenerMap
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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