gm
github.com/eyazici90/go-mediator
go get github.com/eyazici90/go-mediator
gm

github.com/eyazici90/go-mediator

Simple mediator implementation in go

by Emre Yazıcı

v0.0.0-20211025073043-68845d9ec5d5 (see all)License:MIT
go get github.com/eyazici90/go-mediator
Readme

go-mediator

Simple mediator implementation in go.

In-process messaging with behaviours.

Commands

type CreateOrderCommand struct {

Id string `validate:"required,min=10"`

}

func (CreateOrderCommand) Key() string { return "CreateOrderCommand" }

  

type CreateOrderCommandHandler struct {

}

func NewCreateOrderCommandHandler() CreateOrderCommandHandler {

return CreateOrderCommandHandler{}

}

func (CreateOrderCommandHandler) Handle(ctx context.Context, msg mediator.Message) error {

//Do something

return nil

}

Behaviours

PipelineBehaviour interface implementation usage

type Logger struct{}

func NewLogger() *Logger { return &Logger{} }

func (l *Logger) Process(ctx context.Context, msg mediator.Message, next mediator.Next) error {

log.Println("Pre Process!")

result := next(ctx)

log.Println("Post Process")

return result

}

m, err := mediator.New(mediator.WithBehaviour(behaviour.NewLogger()))

Func based usage

m, err := mediator.New(mediator.WithBehaviourFunc(func(ctx context.Context, msg mediator.Message, next mediator.Next) error {

log.Println("Pre Process!")

next(ctx)

log.Println("Post Process")

return  nil

}))

Usages

m, err := mediator.New(
mediator.WithBehaviour(behaviour.NewLogger()),
mediator.WithBehaviour(behaviour.NewValidator()),
mediator.WithHandler(FakeCommand{}, NewFakeCommandCommandHandler(r)),
)

cmd := FakeCommand{   
Name: "Amsterdam",  
}

ctx := context.Background()

err := m.Send(ctx, cmd)

Func based usage

m, err  := mediator.New(mediator.WithBehaviourFunc(func(ctx context.Context, cmd mediator.Message, next mediator.Next) error {
log.Println("Pre Process - 1!")

next(ctx)

log.Println("Post Process - 1")
return  nil
}))

Examples

Simple

TBD...

GitHub Stars

11

LAST COMMIT

7mos ago

MAINTAINERS

0

CONTRIBUTORS

2

OPEN ISSUES

1

OPEN PRs

0
VersionTagPublished
v0.0.0-20211025073043-68845d9ec5d5
7mos ago
v0.0.0-20210919145606-552daf8a9325
8mos ago
v0.0.0-20210917231127-e68746b7e144
8mos ago
v0.0.0-20210729210745-03cf21e80734
10mos ago
No alternatives found
No tutorials found
Add a tutorial