api

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 14 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Polymorphic request encoding to include type information.
	Polymorphic = miruken.Options(Options{
		Polymorphism: miruken.Set(PolymorphismRoot),
	})

	// ToTypeInfo requests the type discriminator for a type.
	ToTypeInfo = maps.To("type:info")
)
View Source
var (
	ToJson   = maps.To("application/json")
	FromJson = maps.From("application/json")
)
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 GoPolymorphismMapper added in v0.22.0

type GoPolymorphismMapper struct{}

GoPolymorphismMapper provides polymorphic support for GO types.

func (*GoPolymorphismMapper) Dynamic added in v0.22.0

func (m *GoPolymorphismMapper) Dynamic(
	_ *struct {
		miruken.Strict
		creates.It
	}, create *creates.It,
	ctx miruken.HandleContext,
) any

func (*GoPolymorphismMapper) Static added in v0.22.0

func (m *GoPolymorphismMapper) Static(
	_ *struct {
		miruken.Strict
		b     creates.It `key:"bool"`
		i     creates.It `key:"int"`
		i8    creates.It `key:"int8"`
		i16   creates.It `key:"int16"`
		i32   creates.It `key:"int32"`
		i64   creates.It `key:"int64"`
		ui    creates.It `key:"uint"`
		ui8   creates.It `key:"uint8"`
		ui16  creates.It `key:"uint16"`
		ui32  creates.It `key:"uint32"`
		ui64  creates.It `key:"uint64"`
		f32   creates.It `key:"float32"`
		f64   creates.It `key:"float64"`
		st    creates.It `key:"string"`
		a     creates.It `key:"interface {}"`
		bs    creates.It `key:"[]bool"`
		is    creates.It `key:"[]int"`
		i8s   creates.It `key:"[]int8"`
		i16s  creates.It `key:"[]int16"`
		i32s  creates.It `key:"[]int32"`
		i64s  creates.It `key:"[]int64"`
		uis   creates.It `key:"[]uint"`
		ui8s  creates.It `key:"[]uint8"`
		ui16s creates.It `key:"[]uint16"`
		ui32s creates.It `key:"[]uint32"`
		ui64s creates.It `key:"[]uint64"`
		f32s  creates.It `key:"[]float32"`
		f64s  creates.It `key:"[]float64"`
		sts   creates.It `key:"[]string"`
		as    creates.It `key:"[]interface {}"`
	}, create *creates.It,
) any

func (*GoPolymorphismMapper) TypeInfo added in v0.22.0

func (m *GoPolymorphismMapper) TypeInfo(
	_ *struct {
		maps.It
		maps.Format `to:"type:info"`
	}, maps *maps.It,
) (TypeFieldInfo, error)

TypeInfo uses package and name to generate type metadata.

type Installer

type Installer struct{}

Installer enables core api support.

func (*Installer) Install

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

type MalformedErrorError added in v0.22.0

type MalformedErrorError struct {
	Culprit any
}

MalformedErrorError reports an invalid error payload.

func (*MalformedErrorError) Error added in v0.22.0

func (e *MalformedErrorError) Error() string

type Message added in v0.11.0

type Message struct {
	Payload any
}

Message is an envelope for polymorphic payloads.

type Options added in v0.18.0

type Options struct {
	Polymorphism   miruken.Option[Polymorphism]
	TypeInfoFormat string
	TypeFieldValue string
}

Options provide options for controlling api messaging.

type PassThroughRouter

type PassThroughRouter struct{}

func (*PassThroughRouter) Pass

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

type Polymorphism added in v0.20.0

type Polymorphism uint8

Polymorphism is an enum that defines how type discriminators are included in polymorphic messages.

const (
	PolymorphismNone Polymorphism = 0
	PolymorphismRoot Polymorphism = 1 << iota
)

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) Concurrent added in v0.22.0

func (s *Scheduler) Concurrent(
	_ *handles.It, concurrent ConcurrentBatch,
	composer miruken.Handler,
) *promise.Promise[ScheduledResult]

func (*Scheduler) Constructor

func (s *Scheduler) Constructor(
	_ *struct {
		provides.It
		provides.Single
	},
)

func (*Scheduler) New added in v0.22.0

func (s *Scheduler) New(
	_ *struct {
		cb creates.It `key:"api.ConcurrentBatch"`
		sb creates.It `key:"api.SequentialBatch"`
		sr creates.It `key:"api.ScheduledResult"`
		p  creates.It `key:"api.Published"`
	}, create *creates.It,
) any

func (*Scheduler) Publish added in v0.22.0

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

func (*Scheduler) Sequential added in v0.22.0

func (s *Scheduler) Sequential(
	_ *handles.It, 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(
	_ *handles.It, drop *stashDrop,
)

Drop removes an item by key.

func (*Stash) Get

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

Get retrieves an item by key. Build 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 {
		provides.It
		miruken.Strict
	}, p *provides.It,
) any

Provide retrieves an item by key.

func (*Stash) Put

func (s *Stash) Put(
	_ *handles.It, put *stashPut,
)

Put stores an item by key.

type Surrogate added in v0.22.0

type Surrogate interface {
	Original(composer miruken.Handler) (any, error)
}

Surrogate replaces a value with another for api transmission.

type TypeFieldInfo added in v0.16.0

type TypeFieldInfo struct {
	TypeField   string
	TypeValue   string
	ValuesField string
}

TypeFieldInfo defines metadata for polymorphic serialization.

type UnknownTypeIdError added in v0.21.0

type UnknownTypeIdError struct {
	TypeId string
	Reason error
}

UnknownTypeIdError reports an invalid type discriminator.

func (*UnknownTypeIdError) Error added in v0.21.0

func (e *UnknownTypeIdError) Error() string

func (*UnknownTypeIdError) Unwrap added in v0.21.0

func (e *UnknownTypeIdError) Unwrap() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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