mediatr

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: MIT Imports: 3 Imported by: 0

README

Go codecov Go Report Card

Command handler without return values

err := mediator.Register(func(command FooEvent){
    return nil
})

Command handler can return error

err := mediator.Register(func(command FooEvent) error{
    return errors.New("db error")
})

Command handler can return error and result(any type)

err := mediator.Register(func(command FooEvent) (string,error){
    return "command executed", nil
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mediator

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

Mediator represents mediator for commands and domain events.

func New

func New() Mediator

New return new instance of mediator.

func (Mediator) Publish

func (m Mediator) Publish(ctx context.Context, event ...interface{}) error

Publish publishes specified domain event to subscribers.

func (Mediator) Register

func (m Mediator) Register(handler interface{}) error

Register registers command handler. Command type is detected by argument of handler.

func (Mediator) Send

func (m Mediator) Send(ctx context.Context, command interface{}) (interface{}, error)

Send sent command to handler.

func (Mediator) Subscribe

func (m Mediator) Subscribe(subscription interface{})

Subscribe add subscription for domain event. Type of event is detected by arguments of handler.

Jump to

Keyboard shortcuts

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