command

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package command contains types and interfaces for implementing Command Handlers, necessary for producing side effects in your Aggregates and system, and implement your Domain's business logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command message.Message

Command is a specific kind of Message that represents an intent. Commands should be phrased in the present, imperative tense, such as "ActivateUser" or "CreateOrder".

type Envelope

type Envelope[T Command] message.Envelope[T]

Envelope carries both a Command and some optional Metadata attached to it.

func FromGenericEnvelope

func FromGenericEnvelope[T Command](cmd GenericEnvelope) (Envelope[T], bool)

FromGenericEnvelope attempts to type-cast a GenericEnvelope instance into a strongly-typed Command Envelope.

A boolean guard is returned to signal whether the type-casting was successful or not.

func ToEnvelope

func ToEnvelope[T Command](cmd T) Envelope[T]

ToEnvelope is a convenience function that wraps the provided Command type into an Envelope, with no metadata attached to it.

func (Envelope[T]) ToGenericEnvelope

func (cmd Envelope[T]) ToGenericEnvelope() GenericEnvelope

ToGenericEnvelope returns a GenericEnvelope version of the current Envelope instance.

type GenericEnvelope

type GenericEnvelope Envelope[Command]

GenericEnvelope is a Command Envelope that depends solely on the Command interface, not a specific generic Command type.

type Handler

type Handler[T Command] interface {
	Handle(ctx context.Context, cmd Envelope[T]) error
}

Handler is the interface that defines a Command Handler, a component that receives a specific kind of Command and executes the business logic related to that particular Command.

type HandlerFunc

type HandlerFunc[T Command] func(context.Context, Envelope[T]) error

HandlerFunc is a functional type that implements the Handler interface. Useful for testing and stateless Handlers.

func (HandlerFunc[T]) Handle

func (fn HandlerFunc[T]) Handle(ctx context.Context, cmd Envelope[T]) error

Handle handles the provided Command through the functional Handler.

Jump to

Keyboard shortcuts

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