Documentation ¶
Overview ¶
Package usecase defines use case interactor.
Index ¶
- func As(interactor Interactor, target interface{}) bool
- type Error
- type HasDescription
- type HasExpectedErrors
- type HasInputPort
- type HasIsDeprecated
- type HasName
- type HasOutputPort
- type HasTags
- type HasTitle
- type Info
- func (i Info) Description() string
- func (i Info) ExpectedErrors() []error
- func (i Info) IsDeprecated() bool
- func (i Info) Name() string
- func (i *Info) SetDescription(description string)
- func (i *Info) SetExpectedErrors(expectedErrors ...error)
- func (i *Info) SetIsDeprecated(isDeprecated bool)
- func (i *Info) SetName(name string)
- func (i *Info) SetTags(tags ...string)
- func (i *Info) SetTitle(title string)
- func (i Info) Tags() []string
- func (i Info) Title() string
- type Interact
- type Interactor
- type Middleware
- type MiddlewareFunc
- type OutputWithEmbeddedWriter
- type OutputWithNoContent
- type OutputWithWriter
- type WithInput
- type WithOutput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
func As(interactor Interactor, target interface{}) bool
As finds the first Interactor in Interactor's chain that matches target, and if so, sets target to that Interactor value and returns true.
An Interactor matches target if the Interactor's concrete value is assignable to the value pointed to by target.
As will panic if target is not a non-nil pointer to either a type that implements Interactor, or to any interface type.
Types ¶
type Error ¶
Error is an error with contextual information.
func (Error) AppErrCode ¶
AppErrCode returns application level error code.
type HasDescription ¶
type HasDescription interface {
Description() string
}
HasDescription declares description.
type HasExpectedErrors ¶
type HasExpectedErrors interface {
ExpectedErrors() []error
}
HasExpectedErrors declares errors that are expected to cause use case failure.
type HasInputPort ¶
type HasInputPort interface {
// InputPort returns sample of input value, e.g. new(MyInput).
InputPort() interface{}
}
HasInputPort declares input port.
type HasIsDeprecated ¶
type HasIsDeprecated interface {
IsDeprecated() bool
}
HasIsDeprecated declares status of deprecation.
type HasOutputPort ¶
type HasOutputPort interface {
// OutputPort returns sample of output value, e.g. new(MyOutput).
OutputPort() interface{}
}
HasOutputPort declares output port.
type Info ¶
type Info struct {
// contains filtered or unexported fields
}
Info exposes information about use case.
func (Info) ExpectedErrors ¶
ExpectedErrors implements HasExpectedErrors.
func (Info) IsDeprecated ¶
IsDeprecated implements HasIsDeprecated.
func (*Info) SetDescription ¶
SetDescription sets use case description.
func (*Info) SetExpectedErrors ¶
SetExpectedErrors sets errors that are expected to cause use case failure.
func (*Info) SetIsDeprecated ¶
SetIsDeprecated sets status of deprecation.
type Interactor ¶
type Interactor interface { // Interact sets output port value with regards to input port value or fails. Interact(ctx context.Context, input, output interface{}) error }
Interactor orchestrates the flow of data to and from the entities, and direct those entities to use their enterprise wide business rules to achieve the goals of the use case.
func Wrap ¶
func Wrap(interactor Interactor, mw ...Middleware) Interactor
Wrap decorates Interactor with Middlewares.
Having arguments i, mw1, mw2 the order of invocation is: mw1, mw2, i, mw2, mw1. Middleware mw1 can find behaviors of mw2 with As, but not vice versa.
type Middleware ¶
type Middleware interface {
Wrap(interactor Interactor) Interactor
}
Middleware creates decorated use case interactor.
type MiddlewareFunc ¶
type MiddlewareFunc func(next Interactor) Interactor
MiddlewareFunc makes Middleware from function.
func (MiddlewareFunc) Wrap ¶
func (mwf MiddlewareFunc) Wrap(interactor Interactor) Interactor
Wrap decorates use case interactor.
type OutputWithEmbeddedWriter ¶
OutputWithEmbeddedWriter implements streaming use case output.
func (*OutputWithEmbeddedWriter) SetWriter ¶
func (o *OutputWithEmbeddedWriter) SetWriter(w io.Writer)
SetWriter implements OutputWithWriter.
type OutputWithNoContent ¶
type OutputWithNoContent struct {
// contains filtered or unexported fields
}
OutputWithNoContent is embeddable structure to provide conditional output discard state.
func (OutputWithNoContent) NoContent ¶
func (o OutputWithNoContent) NoContent() bool
NoContent returns output discard state.
func (*OutputWithNoContent) SetNoContent ¶
func (o *OutputWithNoContent) SetNoContent(enabled bool)
SetNoContent controls output discard state.
type OutputWithWriter ¶
OutputWithWriter defines output with streaming writer.
type WithInput ¶
type WithInput struct {
Input interface{}
}
WithInput is an embeddable implementation of HasInputPort.
type WithOutput ¶
type WithOutput struct {
Output interface{}
}
WithOutput is an embeddable implementation of HasOutputPort.
func (WithOutput) OutputPort ¶
func (wi WithOutput) OutputPort() interface{}
OutputPort implements HasOutputPort.