events

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package events provides emitter adapters for services

The events package's structures are self-initialized by fx and bootstrapper. Fields are populated via yaml values or env variables. Env variables overwrite yaml configuration.

Package events provides emitter adapters for services

The events package's structures are self-initialized by fx and bootstrapper. Fields are populated via yaml values or env variables. Env variables overwrite yaml configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Emitter

type Emitter interface {
	// On is a subscription mechanism.
	// Takes an event name and a handler to process that event.
	On(name string, listener Listener)
	// Fire is a publication mechanism.
	// Takes an event name and a payload to be processed.
	Fire(name string, payload map[string]any)
}

An Emitter provides basic contracts for event publishing/subscribing. The implementation structure is expected to be initialized automatically by fx and bootstrapper

func NewEmitter

func NewEmitter() Emitter

An Emitter constructor. Called automatically by fx and bootstrapper.

Returns an emitter implementation based on configuration. By default returns a gokit emitter.

func NewGoKitEmitter

func NewGoKitEmitter() Emitter

A GoKit Emitter constructor. Called automatically by fx and bootstrapper.

Returns an Emitter compliant implementation based on cache configuration.

type Event

type Event interface {
	// Name returns event name.
	Name() string
	// Get returns a payload by its key.
	Get(key string) any
	// Add adds a payload by its key.
	Add(key string, val any)
	// Abort interrupts event handling.
	Abort(bool)
	// IsAborted returns aborted flag.
	IsAborted() bool
}

An Event provides basic contracts for event handling. The implementation structure is expected to be initialized automatically by fx and bootstrapper.

type Listener

type Listener interface {
	// Handle is an entry point for event handling.
	// Returns the first encountered error.
	//
	// A successful Handle return err == nil.
	Handle(e Event) error
}

A Listener provides basic contracts for event listeners. The implementation structure is expected to be initialized automatically by fx and bootstrapper

Jump to

Keyboard shortcuts

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