cqs

package
v0.0.0-...-aba061b Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: GPL-3.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppError

type AppError struct {
	Name   string      `json:"name"`
	Input  interface{} `json:"input"`
	ErrMsg string      `json:"err_msg"`
}

AppError is a query/command hnd error with context

type BasicAggregateRoot

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

func NewBasicAggregateRoot

func NewBasicAggregateRoot() BasicAggregateRoot

NewBasicAggregateRoot is a constructor

func (*BasicAggregateRoot) ClearEvents

func (b *BasicAggregateRoot) ClearEvents()

ClearEvents removes all events from the aggregate root. It's exported for testing purposes.

func (BasicAggregateRoot) CreatedAt

func (b BasicAggregateRoot) CreatedAt() vo.Time

CreatedAt is a getter

func (*BasicAggregateRoot) Events

func (b *BasicAggregateRoot) Events() []Event

Events is a getter

func (*BasicAggregateRoot) Hydrate

func (b *BasicAggregateRoot) Hydrate(createdAt vo.Time, events []Event)

Hydrate fills the BasicAggregateRoot fields

func (*BasicAggregateRoot) Record

func (b *BasicAggregateRoot) Record(evs ...Event)

type BasicEvent

type BasicEvent struct {
	IDAttr              uuid.UUID `json:"id"`
	NameAttr            EventName `json:"name"`
	AtAttr              vo.Time   `json:"at"`
	AggregateRootIDAttr string    `json:"aggregate_root_id"`
}

BasicEvent is the minimal domain event struct.

func NewBasicEvent

func NewBasicEvent(name EventName, id uuid.UUID, aggRootID string) BasicEvent

NewBasicEvent is the constructor for the type.

func (BasicEvent) AggregateRootID

func (b BasicEvent) AggregateRootID() string

AggregateRootID is a getter

func (BasicEvent) EventAt

func (b BasicEvent) EventAt() vo.Time

EventAt is a getter

func (BasicEvent) EventID

func (b BasicEvent) EventID() uuid.UUID

EventID is a getter

func (BasicEvent) EventName

func (b BasicEvent) EventName() string

EventName is a getter

type Command

type Command interface {
	Name() string
}

Command is the interface for identifying commands by name.

type CommandHandler

type CommandHandler interface {
	Handle(ctx context.Context, cmd Command) ([]Event, error)
}

CommandHandler is self-described

type CommandHandlerFunc

type CommandHandlerFunc func(ctx context.Context, cmd Command) ([]Event, error)

CommandHandlerFunc is a function that implements CommandHandler interface.

func (CommandHandlerFunc) Handle

func (f CommandHandlerFunc) Handle(ctx context.Context, cmd Command) ([]Event, error)

Handle is the CommandHandler interface implementation.

type CommandHandlerMiddleware

type CommandHandlerMiddleware func(h CommandHandler) CommandHandler

func CommandHandlerMultiMiddleware

func CommandHandlerMultiMiddleware(middlewares ...CommandHandlerMiddleware) CommandHandlerMiddleware

CommandHandlerMultiMiddleware applies a sequence of middlewares to a given command handler.

func NewCommandHndErrorMiddleware

func NewCommandHndErrorMiddleware(logger *zerolog.Logger) CommandHandlerMiddleware

type Event

type Event interface {
	EventID() uuid.UUID
	EventName() string
	EventAt() vo.Time
	AggregateRootID() string
}

Event is self-described

type EventBus

type EventBus map[string][]EventListener

EventBus subscribe events with event listeners, and dispatch them.

func NewEventBus

func NewEventBus() EventBus

NewEventBus is a constructor

func (EventBus) Dispatch

func (e EventBus) Dispatch(ctx context.Context, ev Event) error

Dispatch execute event listeners from event

func (EventBus) Subscribe

func (e EventBus) Subscribe(ev Event, listeners ...EventListener)

Subscribe map event to event listeners

type EventFactory

type EventFactory func() Event

EventFactory must return a typed event.

type EventListener

type EventListener interface {
	Listen(ctx context.Context, ev Event) error
}

EventListener is self-described

type EventName

type EventName string

EventName is self-described

func (EventName) String

func (e EventName) String() string

type EventsRepositoryError

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

EventsRepositoryError is self-described

func NewEventsRepositoryError

func NewEventsRepositoryError(operation string, err error) EventsRepositoryError

NewEventsRepositoryError is a constructor

func (EventsRepositoryError) Error

func (e EventsRepositoryError) Error() string

type InvalidCommandError

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

InvalidCommandError should be returned by the implementations of the interface when the handler does not receive the needed command.

func NewInvalidCommandError

func NewInvalidCommandError(expected string, had string) InvalidCommandError

NewInvalidCommandError is a constructor

func (InvalidCommandError) Error

func (e InvalidCommandError) Error() string

type InvalidQueryError

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

InvalidQueryError is self-described

func NewInvalidQueryError

func NewInvalidQueryError(expected string, had string) InvalidQueryError

NewInvalidQueryError is a constructor

func (InvalidQueryError) Error

func (e InvalidQueryError) Error() string

type Query

type Query interface {
	Name() string
}

Query is the interface to identify the DTO for a given query by name.

type QueryHandler

type QueryHandler interface {
	Handle(ctx context.Context, query Query) (any, error)
}

QueryHandler is the interface for handling queries.

type QueryHandlerMiddleware

type QueryHandlerMiddleware func(h QueryHandler) QueryHandler

QueryHandlerMiddleware is a type for decorating QueryHandlers

func NewQueryHndErrorMiddleware

func NewQueryHndErrorMiddleware(logger *zerolog.Logger) QueryHandlerMiddleware

NewQueryHndErrorMiddleware is a middleware constructor to log a contextualized query handler error

type QueryName

type QueryName string

QueryName is string to identify a given query when it has not input parameters.

func (QueryName) Name

func (qn QueryName) Name() string

Name implements Query interface

type UnknownEventToDispatchError

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

UnknownEventToDispatchError is self-described

func (UnknownEventToDispatchError) Error

Jump to

Keyboard shortcuts

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