package app

import "github.com/go-arrower/arrower/app"

Package app provides common decorators for use cases in the application layer.

Index

Constants

const CtxValidated ctx2.CTXKey = "arrower.validated"

Functions

func PassedValidation

func PassedValidation(ctx context.Context) bool

PassedValidation is a helper giving you feedback, if a request passed validation of this middleware. Use it in case you want to ensure that this middleware was called before continuing with your business logic. It can help to reduce the amount of "magic" that this middleware introduces to your code and safe guard you from a potential wrong setup of dependencies.

Types

type Command

type Command[C any] interface {
	H(ctx context.Context, cmd C) error
}

Command produces side effects, e.g. mutate state.

func NewInstrumentedCommand

func NewInstrumentedCommand[C any](
	traceProvider trace.TracerProvider,
	meterProvider metric.MeterProvider,
	logger alog.Logger,
	cmd Command[C],
) Command[C]

NewInstrumentedCommand is a convenience helper for easy dependency setup. The order of dependencies represents the order of calling.

func NewLoggedCommand

func NewLoggedCommand[C any](logger alog.Logger, cmd Command[C]) Command[C]

func NewMeteredCommand

func NewMeteredCommand[C any](meterProvider metric.MeterProvider, req Command[C]) Command[C]

func NewTracedCommand

func NewTracedCommand[C any](traceProvider trace.TracerProvider, cmd Command[C]) Command[C]

func NewTxCommand

func NewTxCommand[C any](pgx *pgxpool.Pool, cmd Command[C]) Command[C]

func NewValidatedCommand

func NewValidatedCommand[C any](validate *validator.Validate, cmd Command[C]) Command[C]

func TestCommandHandler

func TestCommandHandler[C any](handlerFunc unaryHandlerFunc[C]) Command[C]

func TestFailureCommandHandler

func TestFailureCommandHandler[C any]() Command[C]

func TestSuccessCommandHandler

func TestSuccessCommandHandler[C any]() Command[C]

type Job

type Job[J any] interface {
	H(ctx context.Context, job J) error
}

Job produces side effects.

func NewInstrumentedJob

func NewInstrumentedJob[J any](
	traceProvider trace.TracerProvider,
	meterProvider metric.MeterProvider,
	logger alog.Logger,
	job Job[J],
) Job[J]

NewInstrumentedJob is a convenience helper for easy dependency setup. The order of dependencies represents the order of calling.

func NewLoggedJob

func NewLoggedJob[J any](logger alog.Logger, job Job[J]) Job[J]

func NewMeteredJob

func NewMeteredJob[J any](meterProvider metric.MeterProvider, req Job[J]) Job[J]

func NewTracedJob

func NewTracedJob[J any](traceProvider trace.TracerProvider, job Job[J]) Job[J]

func NewValidatedJob

func NewValidatedJob[J any](validate *validator.Validate, job Job[J]) Job[J]

func TestFailureJobHandler

func TestFailureJobHandler[J any]() Job[J]

func TestJobHandler

func TestJobHandler[J any](handlerFunc unaryHandlerFunc[J]) Job[J]

func TestSuccessJobHandler

func TestSuccessJobHandler[J any]() Job[J]

type Query

type Query[Q any, Res any] interface {
	H(ctx context.Context, query Q) (Res, error)
}

Query does not produce side effects and returns data.

func NewInstrumentedQuery

func NewInstrumentedQuery[Q any, Res any](
	traceProvider trace.TracerProvider,
	meterProvider metric.MeterProvider,
	logger alog.Logger,
	query Query[Q, Res],
) Query[Q, Res]

NewInstrumentedQuery is a convenience helper for easy dependency setup. The order of dependencies represents the order of calling.

func NewLoggedQuery

func NewLoggedQuery[Q any, Res any](logger alog.Logger, query Query[Q, Res]) Query[Q, Res]

func NewMeteredQuery

func NewMeteredQuery[Q any, Res any](meterProvider metric.MeterProvider, query Query[Q, Res]) Query[Q, Res]

func NewTracedQuery

func NewTracedQuery[Q any, Res any](traceProvider trace.TracerProvider, query Query[Q, Res]) Query[Q, Res]

func NewValidatedQuery

func NewValidatedQuery[Q any, Res any](validate *validator.Validate, query Query[Q, Res]) Query[Q, Res]

func TestFailureQueryHandler

func TestFailureQueryHandler[Q any, Res any]() Query[Q, Res]

func TestQueryHandler

func TestQueryHandler[Q any, Res any](handlerFunc dualHandlerFunc[Q, Res]) Query[Q, Res]

func TestSuccessQueryHandler

func TestSuccessQueryHandler[Q any, Res any]() Query[Q, Res]

type Request

type Request[Req any, Res any] interface {
	H(ctx context.Context, req Req) (Res, error)
}

Request can produce side effects and return data.

func NewInstrumentedRequest

func NewInstrumentedRequest[Req any, Res any](
	traceProvider trace.TracerProvider,
	meterProvider metric.MeterProvider,
	logger alog.Logger,
	cmd Request[Req, Res],
) Request[Req, Res]

NewInstrumentedRequest is a convenience helper for easy dependency setup. The order of dependencies represents the order of calling.

func NewLoggedRequest

func NewLoggedRequest[Req any, Res any](logger alog.Logger, req Request[Req, Res]) Request[Req, Res]

func NewMeteredRequest

func NewMeteredRequest[Req any, Res any](meterProvider metric.MeterProvider, req Request[Req, Res]) Request[Req, Res]

func NewTracedRequest

func NewTracedRequest[Req any, Res any](traceProvider trace.TracerProvider, req Request[Req, Res]) Request[Req, Res]

func NewTxRequest

func NewTxRequest[Req any, Res any](pgx *pgxpool.Pool, req Request[Req, Res]) Request[Req, Res]

func NewValidatedRequest

func NewValidatedRequest[Req any, Res any](validate *validator.Validate, req Request[Req, Res]) Request[Req, Res]

func TestFailureRequestHandler

func TestFailureRequestHandler[Req any, Res any]() Request[Req, Res]

func TestRequestHandler

func TestRequestHandler[Req any, Res any](handlerFunc dualHandlerFunc[Req, Res]) Request[Req, Res]

func TestSuccessRequestHandler

func TestSuccessRequestHandler[Req any, Res any]() Request[Req, Res]

Source Files

handlers.go logger.decorator.go metric.decorator.go testing.go tracer.decorator.go tx.decorator.go validation.decorator.go

Version
v0.0.0-20250311203644-ab26c1152cb4 (latest)
Published
Mar 11, 2025
Platform
linux/amd64
Imports
16 packages
Last checked
1 week ago

Tools for package owners.