hexago

package module
v0.0.0-...-14b8d05 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 4 Imported by: 0

README

hexago

A painless way to achieve the clean architecture in golang

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewId

func NewId() uuid.UUID

Types

type AggRoot

type AggRoot interface {
	Identifiable
	Pull() []Event
}

AggRoot is just an abbreviation for AggregateRoot. In DDD terms it clusters domain entities so that they act like one single unit. It has ability to capturing events. The brain of the business and handling core considerations goes here in AggRoot.

type Cmd

type Cmd struct {
	Name    string
	Payload interface{}
}

Cmd is just Command's abbreviation, in the clean architecture there's a layer which is responsible for handling system use cases. It is common to call this layer `application` layer. It acts like an orchestrator which connects different layers. A common pattern for implementing the application layer is, Command Query Responsibility Segregation or CQRS. The Cmd struct, tries to act like a command.

func NewCmd

func NewCmd(name string, payload interface{}) Cmd

NewCmd creates a new Cmd.

type CmdBag

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

CmdBag just holds a mapping between Cmd and CmdHandlerFactory

func NewCmdBag

func NewCmdBag() *CmdBag

NewCmdBag creates an empty CmdBag.

func (*CmdBag) Add

func (cb *CmdBag) Add(cmd string, f CmdHandlerFactory)

func (*CmdBag) FactoryFor

func (cb *CmdBag) FactoryFor(cmd string) (CmdHandlerFactory, error)

type CmdBus

type CmdBus interface {
	Handle(Cmd) (string, error)
}

CmdBus decouples Cmd from its execution, dependencies, side effects.

type CmdHandler

type CmdHandler interface {
	Handle(Cmd) (string, error)
}

CmdHandler is considered for being responsible to handling, one single Cmd [command]. It's common to use the domain repositories in order to ship aggregates, and using the domain functionalities to handling use cases.

type CmdHandlerFactory

type CmdHandlerFactory func() CmdHandler

CmdHandlerFactory is a function that creates CmdHandler.

type Event

type Event struct {
	Identifier uuid.UUID
	Name       string
	At         time.Time
	Payload    interface{}
}

Event is like an important happening in the domain. It can be implied a change state, or something like that.

func (Event) Id

func (e Event) Id() uuid.UUID

type EventBag

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

EventBag just holds a mapping between Event and EventHandler

func NewEventBag

func NewEventBag() *EventBag

NewEventBag creates an empty EventBag.

func (*EventBag) Add

func (e *EventBag) Add(event string, handlers ...EventHandlerFactory)

func (*EventBag) FactoryFor

func (e *EventBag) FactoryFor(event string) []EventHandlerFactory

type EventHandler

type EventHandler interface {
	Handle(Event)
}

type EventHandlerFactory

type EventHandlerFactory func() EventHandler

type Identifiable

type Identifiable interface {
	Id() uuid.UUID
}

type InMemoryBus

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

func NewInMemoryBus

func NewInMemoryBus(cmd *CmdBag, events *EventBag) InMemoryBus

NewInMemoryBus creates a fresh bus without any captured events.

func (InMemoryBus) Handle

func (i InMemoryBus) Handle(cmd Cmd) (string, error)

type Repo

type Repo interface {
	Seen() []AggRoot
}

Repo is responsible take and bring the domain objects and AggRoot's.

Jump to

Keyboard shortcuts

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