api

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 10 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FromError = miruken.To("api:error")
	ToError   = miruken.From("api:error")
)
View Source
var (
	ErrMissingResponse = errors.New("missing batch response")
)

Functions

func Concurrent

func Concurrent(
	handler miruken.Handler,
	requests ...any,
) *promise.Promise[[]either.Either[error, any]]

Concurrent processes a batch of requests concurrently. Returns a batch of corresponding responses (or errors).

func Failure

func Failure(val error) either.Either[error, any]

Failure returns a new failed result.

func Feature

func Feature(
	config ...func(installer *Installer),
) miruken.Feature

func Post

func Post(
	handler miruken.Handler,
	message any,
) (p *promise.Promise[miruken.Void], err error)

Post sends a message without an expected response. A new Stash is created to manage any transit state. Returns an empty promise if the call is asynchronous.

func Publish

func Publish(
	handler miruken.Handler,
	message any,
) (p *promise.Promise[miruken.Void], err error)

Publish sends a message to all recipients. A new Stash is created to manage any transit state. Returns an empty promise if the call is asynchronous.

func Send

func Send[TResponse any](
	handler miruken.Handler,
	request any,
) (r TResponse, pr *promise.Promise[TResponse], err error)

Send sends a request with an expected response. A new Stash is created to manage any transit state. Returns the TResponse if the call is synchronous or a promise of TResponse if the call is asynchronous.

func Sequential

func Sequential(
	handler miruken.Handler,
	requests ...any,
) *promise.Promise[[]either.Either[error, any]]

Sequential processes a batch of requests sequentially. Returns a batch of corresponding responses (or errors).

func StashDrop

func StashDrop[T any](
	handler miruken.Handler,
) error

func StashDropKey

func StashDropKey(
	handler miruken.Handler,
	key any,
) (err error)

func StashGet

func StashGet[T any](
	handler miruken.Handler,
) (t T, ok bool)

func StashGetKey

func StashGetKey(
	handler miruken.Handler,
	key any,
) (val any, ok bool)

func StashGetOrPut

func StashGetOrPut[T any](
	handler miruken.Handler,
	val T,
) (T, error)

func StashGetOrPutFunc

func StashGetOrPutFunc[T any](
	handler miruken.Handler,
	fun func() (T, *promise.Promise[T]),
) (T, *promise.Promise[T], error)

func StashGetOrPutKey

func StashGetOrPutKey(
	handler miruken.Handler,
	key any,
	val any,
) (any, error)

func StashGetOrPutKeyFunc

func StashGetOrPutKeyFunc(
	handler miruken.Handler,
	key any,
	fun func() (any, *promise.Promise[any]),
) (any, *promise.Promise[any], error)

func StashPut

func StashPut[T any](
	handler miruken.Handler,
	val T,
) error

func StashPutKey

func StashPutKey(
	handler miruken.Handler,
	key any,
	val any,
) error

func Success

func Success[R any](val R) either.Either[error, R]

Success returns a new successful result.

Types

type ConcurrentBatch

type ConcurrentBatch struct {
	Requests []any
}

ConcurrentBatch represents a batch of requests to execute concurrently. The operation returns after all requests are completed and includes all successes and failures.

type ErrorData added in v0.11.0

type ErrorData struct {
	Message string
}

ErrorData is the default error shape.

type Installer

type Installer struct{}

Installer enables api support.

func (*Installer) Install

func (v *Installer) Install(setup *miruken.SetupBuilder) error

type Message added in v0.11.0

type Message struct {
	Payload any
}

Message is envelop for polymorphic messages.

type PassThroughRouter

type PassThroughRouter struct{}

func (*PassThroughRouter) Pass

func (p *PassThroughRouter) Pass(
	_ *struct {
		miruken.Handles
		miruken.SkipFilters
		Routes `scheme:"pass-through"`
	}, routed Routed,
	composer miruken.Handler,
) (any, miruken.HandleResult)

type PolymorphicHandling added in v0.11.0

type PolymorphicHandling uint8

PolymorphicHandling is an enum that determines if messages are augmented with type discriminators.

const (
	PolymorphicHandlingNone PolymorphicHandling = 0
	PolymorphicHandlingRoot PolymorphicHandling = 1 << iota
)

type PolymorphicOptions added in v0.11.0

type PolymorphicOptions struct {
	PolymorphicHandling miruken.Option[PolymorphicHandling]
}

PolymorphicOptions provide options for controlling polymorphic messaging.

type Published

type Published struct {
	Message any
}

Published marks a message to be published to all consumers.

type RouteReply

type RouteReply struct {
	Uri       string
	Responses []any
}

RouteReply holds the responses for a route.

type Routed

type Routed struct {
	Message any
	Route   string
}

Routed wraps a message with route information.

func RouteTo

func RouteTo(message any, route string) Routed

RouteTo wraps the message in a Routed container.

type Routes

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

Routes is a FilterProvider of routesFilter.

func (*Routes) AppliesTo

func (r *Routes) AppliesTo(
	callback miruken.Callback,
) bool

func (*Routes) Filters

func (r *Routes) Filters(
	binding miruken.Binding,
	callback any,
	composer miruken.Handler,
) ([]miruken.Filter, error)

func (*Routes) InitWithTag

func (r *Routes) InitWithTag(tag reflect.StructTag) error

func (*Routes) Required

func (r *Routes) Required() bool

func (*Routes) Satisfies

func (r *Routes) Satisfies(routed Routed) bool

type ScheduledResult

type ScheduledResult struct {
	Responses []either.Either[error, any]
}

ScheduledResult represents the results of a scheduled request. The result is either an error (if fails) or success value.

type Scheduler

type Scheduler struct{}

Scheduler performs the scheduling of requests.

func (*Scheduler) Constructor

func (s *Scheduler) Constructor(
	_ *struct {
		miruken.Provides
		miruken.Singleton
	},
)

func (*Scheduler) HandleConcurrent

func (s *Scheduler) HandleConcurrent(
	_ *miruken.Handles, concurrent ConcurrentBatch,
	composer miruken.Handler,
) *promise.Promise[ScheduledResult]

func (*Scheduler) HandlePublish

func (s *Scheduler) HandlePublish(
	_ *miruken.Handles, publish Published,
	composer miruken.Handler,
) (p *promise.Promise[miruken.Void], err error)

func (*Scheduler) HandleSequential

func (s *Scheduler) HandleSequential(
	_ *miruken.Handles, sequential SequentialBatch,
	composer miruken.Handler,
) *promise.Promise[ScheduledResult]

type SequentialBatch

type SequentialBatch struct {
	Requests []any
}

SequentialBatch represents a batch of requests to execute sequentially. The operation aborts after the first failure and returns the successfully completed responses and first failure.

type Stash

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

Stash is a transient storage of data.

func NewStash

func NewStash(root bool) *Stash

NewStash creates a new Stash. When root is true, retrieval will not fail if not found.

func (*Stash) Drop

func (s *Stash) Drop(
	_ *miruken.Handles, drop *stashDrop,
)

Drop removes an item by key.

func (*Stash) Get

func (s *Stash) Get(
	_ *miruken.Handles, get *stashGet,
) miruken.HandleResult

Get retrieves an item by key. It is considered NotHandled if an item with the key is not found and this Stash is not rooted. This allows retrieval to propagate up the chain.

func (*Stash) NoConstructor

func (s *Stash) NoConstructor()

NoConstructor prevents Stash from being created implicitly.

func (*Stash) Provide

func (s *Stash) Provide(
	_ *struct {
		miruken.Provides
		miruken.Strict
	}, provides *miruken.Provides,
) any

Provide retrieves an item by key.

func (*Stash) Put

func (s *Stash) Put(
	_ *miruken.Handles, put *stashPut,
)

Put stores an item by key.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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