api

package
v0.30.113 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 27 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ToJson encodes a model into json format
	ToJson = maps.To("application/json", nil)

	// FromJson decodes json into a corresponding model
	FromJson = maps.From("application/json", nil)
)
View Source
var (
	// Polymorphic instructs type information to be included.
	Polymorphic = miruken.Options(Options{
		Polymorphism: miruken.Set(PolymorphismRoot),
	})

	// NoPolymorphism instructs type information to be suppressed.
	NoPolymorphism = miruken.Options(Options{
		Polymorphism: miruken.Set(PolymorphismNone),
	})

	// ToTypeInfo formats a value into corresponding type information.
	ToTypeInfo = maps.To("type:info", nil)
)
View Source
var ErrMissingBoundary = errors.New(`multipart: missing "boundary" parameter`)
View Source
var ErrMissingResponse = errors.New("missing batch response")
View Source
var ErrMissingScheme = errors.New("the Routes filter requires a non-empty `schemes` tag")

Functions

func Concurrent

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

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

func Failure

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

Failure returns a new failed result.

func Feature

func Feature(config ...func(*Installer)) setup.Feature

func FormatMediaType added in v0.26.0

func FormatMediaType(format *maps.Format) string

FormatMediaType formats the maps.Format into a media type conforming to RFC 2045 and RFC 2616.

func MergeHeader added in v0.26.0

func MergeHeader(
	header textproto.MIMEHeader,
	metadata map[string]any,
)

MergeHeader merges the supplied key values into the existing mime header.

func NewHeader added in v0.26.0

func NewHeader(
	metadata map[string]any,
) textproto.MIMEHeader

NewHeader creates a mime header from the supplied key values.

func ParseMediaType added in v0.26.0

func ParseMediaType(
	mediaType string,
	direction maps.Direction,
) (*maps.Format, error)

ParseMediaType parses the mediaType into a maps.Format suitable for mapping in the requested direction.

func Post

func Post(
	handler miruken.Handler,
	message any,
) (p *promise.Promise[any], 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[any], 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.Monad[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.Monad[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 Content added in v0.26.0

type Content interface {
	MediaType() string
	Metadata() map[string]any
	Body() any
}

Content is information produced or consumed by an api.

type GoPolymorphism added in v0.24.0

type GoPolymorphism struct{}

GoPolymorphism provides type information using GO types names.

func (*GoPolymorphism) Dynamic added in v0.24.0

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

func (*GoPolymorphism) Static added in v0.24.0

func (m *GoPolymorphism) Static(
	_ *struct {
		creates.Strict
		_ creates.It `key:"bool"`
		_ creates.It `key:"int"`
		_ creates.It `key:"int8"`
		_ creates.It `key:"int16"`
		_ creates.It `key:"int32"`
		_ creates.It `key:"int64"`
		_ creates.It `key:"uint"`
		_ creates.It `key:"uint8"`
		_ creates.It `key:"uint16"`
		_ creates.It `key:"uint32"`
		_ creates.It `key:"uint64"`
		_ creates.It `key:"float32"`
		_ creates.It `key:"float64"`
		_ creates.It `key:"string"`
		_ creates.It `key:"interface {}"`
		_ creates.It `key:"[]bool"`
		_ creates.It `key:"[]int"`
		_ creates.It `key:"[]int8"`
		_ creates.It `key:"[]int16"`
		_ creates.It `key:"[]int32"`
		_ creates.It `key:"[]int64"`
		_ creates.It `key:"[]uint"`
		_ creates.It `key:"[]uint8"`
		_ creates.It `key:"[]uint16"`
		_ creates.It `key:"[]uint32"`
		_ creates.It `key:"[]uint64"`
		_ creates.It `key:"[]float32"`
		_ creates.It `key:"[]float64"`
		_ creates.It `key:"[]string"`
		_ creates.It `key:"[]interface {}"`
	}, create *creates.It,
) any

func (*GoPolymorphism) TypeInfo added in v0.24.0

func (m *GoPolymorphism) TypeInfo(
	_ *struct {
		maps.Format `to:"type:info"`
	}, it *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 (i *Installer) Install(b *setup.Builder) error

type Late added in v0.30.28

type Late struct {
	Value any
}

Late is a container for late polymorphic results. It is used be serializers to explicitly request polymorphic behavior and avoid circular calls with any type.

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 MultipartMapper added in v0.25.0

type MultipartMapper struct{}

MultipartMapper reads and writes 'multipart/*' mime messages from a PartContainer.

func (*MultipartMapper) Read added in v0.25.0

func (m *MultipartMapper) Read(
	_ *struct {
		maps.Format `from:"/multipart//"`
	}, reader io.Reader,
	it *maps.It,
	ctx miruken.HandleContext,
) (Message, error)

func (*MultipartMapper) Write added in v0.26.0

func (m *MultipartMapper) Write(
	_ *struct {
		maps.Format `to:"/multipart//"`
	}, msg Message,
	it *maps.It,
	ctx miruken.HandleContext,
) (io.Writer, error)

func (*MultipartMapper) WriteParts added in v0.26.0

func (m *MultipartMapper) WriteParts(
	_ *struct {
		maps.Format `to:"/multipart//"`
	}, pc PartContainer,
	it *maps.It,
	ctx miruken.HandleContext,
) (io.Writer, error)

type Options added in v0.18.0

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

Options control api message processing.

type Part added in v0.25.0

type Part interface {
	Content
	Filename() string
}

Part represents a piece of a message. Part can be used in a PartContainer or independently to control message encoding.

type PartBuilder added in v0.25.0

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

PartBuilder builds a message Part.

func (*PartBuilder) Body added in v0.26.0

func (b *PartBuilder) Body(
	body any,
) *PartBuilder

func (*PartBuilder) Build added in v0.25.0

func (b *PartBuilder) Build() Part

func (*PartBuilder) Filename added in v0.25.0

func (b *PartBuilder) Filename(
	filename string,
) *PartBuilder

func (*PartBuilder) MediaType added in v0.26.0

func (b *PartBuilder) MediaType(
	mediaType string,
) *PartBuilder

func (*PartBuilder) Metadata added in v0.25.0

func (b *PartBuilder) Metadata(
	metadata map[string]any,
) *PartBuilder

func (*PartBuilder) MetadataStrings added in v0.26.0

func (b *PartBuilder) MetadataStrings(
	metadata map[string][]string,
) *PartBuilder

type PartContainer added in v0.25.0

type PartContainer interface {
	Content
	Parts() map[string][]Part
	MainPart() Part
}

PartContainer stores all the Part's of a message. The main part is typically the message payload.

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 enumerates how type information should be included in 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 ReadPartsBuilder added in v0.25.0

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

ReadPartsBuilder builds a PartContainer for reading Part's.

func (*ReadPartsBuilder) AddPart added in v0.25.0

func (b *ReadPartsBuilder) AddPart(
	key string,
	part Part,
) *ReadPartsBuilder

func (*ReadPartsBuilder) AddParts added in v0.26.0

func (b *ReadPartsBuilder) AddParts(
	parts map[string][]Part,
) *ReadPartsBuilder

func (*ReadPartsBuilder) Build added in v0.25.0

func (b *ReadPartsBuilder) Build() PartContainer

func (*ReadPartsBuilder) MainPart added in v0.25.0

func (b *ReadPartsBuilder) MainPart(
	main Part,
) *ReadPartsBuilder

func (*ReadPartsBuilder) Metadata added in v0.25.0

func (b *ReadPartsBuilder) Metadata(
	metadata map[string]any,
) *ReadPartsBuilder

func (*ReadPartsBuilder) NewPart added in v0.26.0

func (b *ReadPartsBuilder) NewPart() *PartBuilder

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 for routing.

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.Monad[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 {
		_ creates.It `key:"api.ConcurrentBatch"`
		_ creates.It `key:"api.SequentialBatch"`
		_ creates.It `key:"api.ScheduledResult"`
		_ 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[any], 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.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(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 the type information for polymorphic messages.

type UnknownTypeIdError added in v0.21.0

type UnknownTypeIdError struct {
	TypeId string
	Cause  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

type WritePartsBuilder added in v0.25.0

type WritePartsBuilder struct {
	ReadPartsBuilder
}

WritePartsBuilder builds a PartContainer for writing Part's.

func (*WritePartsBuilder) Build added in v0.25.0

func (b *WritePartsBuilder) Build() PartContainer

func (*WritePartsBuilder) MediaType added in v0.26.0

func (b *WritePartsBuilder) MediaType(
	mediaType string,
) *WritePartsBuilder

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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