evt

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NATS_TIMEOUT = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Kind  string `json:"kind" mapstructure:"kind"`
	Value any    `json:"data" mapstructure:"value"`
	Error string `json:"error" mapstructure:"error"`
	Meta  map[string]any
}

func NewErrorEvent

func NewErrorEvent(kind, err string) *Event

func NewEvent

func NewEvent(kind string, value any) *Event

func (Event) Export

func (e Event) Export(v any) error

func (*Event) Get

func (e *Event) Get(key string) any

func (*Event) Set

func (e *Event) Set(key string, value any)

type HandlerFunc

type HandlerFunc func(req *Event) (*Event, error)

func (HandlerFunc) HandleEvent

func (h HandlerFunc) HandleEvent(e *Event) (*Event, error)

type IEventBus

type IEventBus interface {
	Publish(e *Event) error
	Register(kind string, fn HandlerFunc)
	Request(e *Event) (*Event, error)
	Use(mw ...HandlerFunc)
	Close() error
}

type IHandler

type IHandler interface {
	HandleEvent(e *Event) (*Event, error)
}

type NatsEventBus

type NatsEventBus struct {
	// contains filtered or unexported fields
}

NatsEventBus implements IEventBus using nats

func NewNatsEventBus

func NewNatsEventBus(subject string, nc *nats.Conn) *NatsEventBus

func (*NatsEventBus) Close

func (b *NatsEventBus) Close() error

func (*NatsEventBus) Publish

func (b *NatsEventBus) Publish(e *Event) error

Publish sends an event

func (*NatsEventBus) Register

func (b *NatsEventBus) Register(kind string, fn HandlerFunc)

Register a handler for a specific event kind handler is called when an event arrives. To handle publish events, register a handler and don't reply. To handle request events, register a handler and reply.

func (*NatsEventBus) Request

func (b *NatsEventBus) Request(e *Event) (*Event, error)

Request sends an event and waits for a response

func (*NatsEventBus) Use

func (b *NatsEventBus) Use(middleware ...HandlerFunc)

add middleware, middleware is applied in oder and called for each event

Jump to

Keyboard shortcuts

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