cqrs

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: BSD-3-Clause Imports: 0 Imported by: 0

README

CQRS

A extremely simple set of interfaces for cqrs usage:

  • cqrs.CommandHandler
  • cqrs.QueryHandler
  • cqrs.EventHandler

CommandHandler

type ExampleCommand struct {
	Value string
}

type ExampleHandler struct {
	repo ExampleRepo
}

func NewExampleHandler(
	repo ExampleRepo,
) cqrs.CommandHandler[*ExampleCommand] {
	return &ExampleHandler{
		repo:    repo,
	}
}

func (h *ExampleHandler) Handle(command *ExampleCommand) error {
	return repo.DoSomething(command.Value)
}

QueryHandler

type ExampleQuery struct {
	Id string
}

type ExampleHandler struct {
	repo ExampleRepo
}

func NewExampleHandler(
	repo ExampleRepo,
) cqrs.QueryHandler[*ExampleQuery, *Entity] {
	return &ExampleHandler{
		repo:    repo,
	}
}

func (h *ExampleHandler) Handle(query *ExampleQuery) (*Entity, error) {
	return repo.GetExampleEntity(query.Id)
}

EventHandler

type ExampleEvent struct {
	Value string
}

type ExampleHandler struct {
	service ExampleService
}

func NewExampleHandler(
	service ExampleService,
) cqrs.EventHandler[*ExampleEvent] {
	return &ExampleHandler{
		service:    service,
	}
}

func (h *ExampleHandler) Handle(event *ExampleEvent) error {
	return service.Handle(event.Value)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandHandler

type CommandHandler[TCommand any] interface {
	Handle(command TCommand) error
}

type EventHandler

type EventHandler[TEvent any] interface {
	Handle(event TEvent) error
}

type QueryHandler

type QueryHandler[TQuery any, TResult any] interface {
	Handle(query TQuery) (TResult, error)
}

Jump to

Keyboard shortcuts

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