A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pkg.go.dev/github.com/aws/smithy-go/middleware below:

middleware package - github.com/aws/smithy-go/middleware - Go Packages

Package middleware provides transport agnostic middleware for decorating SDK handlers.

The Smithy middleware stack provides ordered behavior to be invoked on an underlying handler. The stack is separated into steps that are invoked in a static order. A step is a collection of middleware that are injected into a ordered list defined by the user. The user may add, insert, swap, and remove a step's middleware. When the stack is invoked the step middleware become static, and their order cannot be modified.

A stack and its step middleware are **not** safe to modify concurrently.

A stack will use the ordered list of middleware to decorate a underlying handler. A handler could be something like an HTTP Client that round trips an API operation over HTTP.

Smithy Middleware Stack

A Stack is a collection of middleware that wrap a handler. The stack can be broken down into discreet steps. Each step may contain zero or more middleware specific to that stack's step.

A Stack Step is a predefined set of middleware that are invoked in a static order by the Stack. These steps represent fixed points in the middleware stack for organizing specific behavior, such as serialize and build. A Stack Step is composed of zero or more middleware that are specific to that step. A step may define its own set of input/output parameters the generic input/output parameters are cast from. A step calls its middleware recursively, before calling the next step in the stack returning the result or error of the step middleware decorating the underlying handler.

* Initialize: Prepares the input, and sets any default parameters as needed, (e.g. idempotency token, and presigned URLs).

* Serialize: Serializes the prepared input into a data structure that can be consumed by the target transport's message, (e.g. REST-JSON serialization).

* Build: Adds additional metadata to the serialized transport message, (e.g. HTTP's Content-Length header, or body checksum). Decorations and modifications to the message should be copied to all message attempts.

* Finalize: Performs final preparations needed before sending the message. The message should already be complete by this stage, and is only alternated to meet the expectations of the recipient, (e.g. Retry and AWS SigV4 request signing).

* Deserialize: Reacts to the handler's response returned by the recipient of the request message. Deserializes the response into a structured type or error above stacks can react to.

Adding Middleware to a Stack Step

Middleware can be added to a step front or back, or relative, by name, to an existing middleware in that stack. If a middleware does not have a name, a unique name will be generated at the middleware and be added to the step.

// Create middleware stack
stack := middleware.NewStack()

// Add middleware to stack steps
stack.Initialize.Add(paramValidationMiddleware, middleware.After)
stack.Serialize.Add(marshalOperationFoo, middleware.After)
stack.Deserialize.Add(unmarshalOperationFoo, middleware.After)

// Invoke middleware on handler.
resp, err := stack.HandleMiddleware(ctx, req.Input, clientHandler)

This section is empty.

This section is empty.

AddSetLoggerMiddleware adds a middleware that will add the provided logger to the middleware context.

ClearStackValues returns a context without any stack values.

GetLogger takes a context to retrieve a Logger from. If no logger is present on the context a logging.Nop logger is returned. If the logger retrieved from context supports the ContextLogger interface, the context will be passed to the WithContext method and the resulting logger will be returned. Otherwise the stored logger is returned as is.

GetOperationName retrieves the operation name from the context. This is typically the operation shape's name from its Smithy model.

GetServiceID retrieves the service ID from the context. This is typically the service shape's name from its Smithy model. Service clients for specific systems (e.g. AWS SDK) may use an alternate designated value.

GetStackValues returns the value pointed to by the key within the stack values, if it is present.

SetLogger sets the provided logger value on the provided ctx.

WithOperationName adds the operation name to the context, scoped to middleware stack values.

This API is called in the client runtime when bootstrapping an operation and should not typically be used directly.

WithServiceID adds a service ID to the context, scoped to middleware stack values.

This API is called in the client runtime when bootstrapping an operation and should not typically be used directly.

WithStackValue adds a key value pair to the context that is intended to be scoped to a stack. Use ClearStackValues to get a new context with all stack values cleared.

type BuildHandler

BuildHandler provides the interface for the next handler the BuildMiddleware will call in the middleware chain.

type BuildHandlerFunc

BuildHandlerFunc provides a wrapper around a function to be used as a build middleware handler.

func (BuildHandlerFunc) HandleBuild

HandleBuild invokes the wrapped function with the provided arguments.

type BuildInput struct {
	Request interface{}
}

BuildInput provides the input parameters for the BuildMiddleware to consume. BuildMiddleware may modify the Request value before forwarding the input along to the next BuildHandler.

BuildMiddleware provides the interface for middleware specific to the serialize step. Delegates to the next BuildHandler for further processing.

BuildMiddlewareFunc returns a BuildMiddleware with the unique ID provided, and the func to be invoked.

type BuildOutput struct {
	Result interface{}
}

BuildOutput provides the result returned by the next BuildHandler.

type BuildStep struct {
	
}

BuildStep provides the ordered grouping of BuildMiddleware to be invoked on a handler.

NewBuildStep returns a BuildStep ready to have middleware for initialization added to it.

Add injects the middleware to the relative position of the middleware group. Returns an error if the middleware already exists.

Clear removes all middleware in the step.

Get retrieves the middleware identified by id. If the middleware is not present, returns false.

func (*BuildStep) HandleMiddleware

HandleMiddleware invokes the middleware by decorating the next handler provided. Returns the result of the middleware and handler being invoked.

Implements Middleware interface.

ID returns the unique name of the step as a middleware.

Insert injects the middleware relative to an existing middleware id. Returns an error if the original middleware does not exist, or the middleware being added already exists.

List returns a list of the middleware in the step.

Remove removes the middleware by id. Returns error if the middleware doesn't exist.

Swap removes the middleware by id, replacing it with the new middleware. Returns the middleware removed, or an error if the middleware to be removed doesn't exist.

type DeserializeHandler

DeserializeHandler provides the interface for the next handler the DeserializeMiddleware will call in the middleware chain.

type DeserializeHandlerFunc

DeserializeHandlerFunc provides a wrapper around a function to be used as a deserialize middleware handler.

func (DeserializeHandlerFunc) HandleDeserialize

HandleDeserialize invokes the wrapped function with the given arguments.

type DeserializeInput struct {
	Request interface{}
}

DeserializeInput provides the input parameters for the DeserializeInput to consume. DeserializeMiddleware should not modify the Request, and instead forward it along to the next DeserializeHandler.

DeserializeMiddleware provides the interface for middleware specific to the serialize step. Delegates to the next DeserializeHandler for further processing.

DeserializeMiddlewareFunc returns a DeserializeMiddleware with the unique ID provided, and the func to be invoked.

type DeserializeOutput struct {
	RawResponse interface{}
	Result      interface{}
}

DeserializeOutput provides the result returned by the next DeserializeHandler. The DeserializeMiddleware should deserialize the RawResponse into a Result that can be consumed by middleware higher up in the stack.

type DeserializeStep struct {
	
}

DeserializeStep provides the ordered grouping of DeserializeMiddleware to be invoked on a handler.

NewDeserializeStep returns a DeserializeStep ready to have middleware for initialization added to it.

Add injects the middleware to the relative position of the middleware group. Returns an error if the middleware already exists.

Clear removes all middleware in the step.

Get retrieves the middleware identified by id. If the middleware is not present, returns false.

func (*DeserializeStep) HandleMiddleware

HandleMiddleware invokes the middleware by decorating the next handler provided. Returns the result of the middleware and handler being invoked.

Implements Middleware interface.

ID returns the unique ID of the step as a middleware.

Insert injects the middleware relative to an existing middleware ID. Returns error if the original middleware does not exist, or the middleware being added already exists.

List returns a list of the middleware in the step.

Remove removes the middleware by id. Returns error if the middleware doesn't exist.

Swap removes the middleware by id, replacing it with the new middleware. Returns the middleware removed, or error if the middleware to be removed doesn't exist.

type FinalizeHandler

FinalizeHandler provides the interface for the next handler the FinalizeMiddleware will call in the middleware chain.

type FinalizeHandlerFunc

FinalizeHandlerFunc provides a wrapper around a function to be used as a finalize middleware handler.

func (FinalizeHandlerFunc) HandleFinalize

HandleFinalize invokes the wrapped function with the given arguments.

type FinalizeInput struct {
	Request interface{}
}

FinalizeInput provides the input parameters for the FinalizeMiddleware to consume. FinalizeMiddleware may modify the Request value before forwarding the FinalizeInput along to the next next FinalizeHandler.

FinalizeMiddleware provides the interface for middleware specific to the serialize step. Delegates to the next FinalizeHandler for further processing.

FinalizeMiddlewareFunc returns a FinalizeMiddleware with the unique ID provided, and the func to be invoked.

type FinalizeOutput struct {
	Result interface{}
}

FinalizeOutput provides the result returned by the next FinalizeHandler.

type FinalizeStep struct {
	
}

FinalizeStep provides the ordered grouping of FinalizeMiddleware to be invoked on a handler.

NewFinalizeStep returns a FinalizeStep ready to have middleware for initialization added to it.

Add injects the middleware to the relative position of the middleware group. Returns an error if the middleware already exists.

Clear removes all middleware in the step.

Get retrieves the middleware identified by id. If the middleware is not present, returns false.

func (*FinalizeStep) HandleMiddleware

HandleMiddleware invokes the middleware by decorating the next handler provided. Returns the result of the middleware and handler being invoked.

Implements Middleware interface.

ID returns the unique id of the step as a middleware.

Insert injects the middleware relative to an existing middleware ID. Returns error if the original middleware does not exist, or the middleware being added already exists.

List returns a list of the middleware in the step.

Remove removes the middleware by id. Returns error if the middleware doesn't exist.

Swap removes the middleware by id, replacing it with the new middleware. Returns the middleware removed, or error if the middleware to be removed doesn't exist.

type Handler

Handler provides the interface for performing the logic to obtain an output, or error for the given input.

func DecorateHandler

DecorateHandler decorates a handler with a middleware. Wrapping the handler with the middleware.

type HandlerFunc

HandlerFunc provides a wrapper around a function pointer to be used as a middleware handler.

func (HandlerFunc) Handle

Handle invokes the underlying function, returning the result.

type InitializeHandler

InitializeHandler provides the interface for the next handler the InitializeMiddleware will call in the middleware chain.

type InitializeHandlerFunc

InitializeHandlerFunc provides a wrapper around a function to be used as an initialize middleware handler.

func (InitializeHandlerFunc) HandleInitialize

HandleInitialize calls the wrapped function with the provided arguments.

type InitializeInput struct {
	Parameters interface{}
}

InitializeInput wraps the input parameters for the InitializeMiddlewares to consume. InitializeMiddleware may modify the parameter value before forwarding it along to the next InitializeHandler.

InitializeMiddleware provides the interface for middleware specific to the initialize step. Delegates to the next InitializeHandler for further processing.

InitializeMiddlewareFunc returns a InitializeMiddleware with the unique ID provided, and the func to be invoked.

type InitializeOutput struct {
	Result interface{}
}

InitializeOutput provides the result returned by the next InitializeHandler.

type InitializeStep struct {
	
}

InitializeStep provides the ordered grouping of InitializeMiddleware to be invoked on a handler.

NewInitializeStep returns an InitializeStep ready to have middleware for initialization added to it.

Add injects the middleware to the relative position of the middleware group. Returns an error if the middleware already exists.

Clear removes all middleware in the step.

Get retrieves the middleware identified by id. If the middleware is not present, returns false.

func (*InitializeStep) HandleMiddleware

HandleMiddleware invokes the middleware by decorating the next handler provided. Returns the result of the middleware and handler being invoked.

Implements Middleware interface.

ID returns the unique ID of the step as a middleware.

Insert injects the middleware relative to an existing middleware ID. Returns error if the original middleware does not exist, or the middleware being added already exists.

List returns a list of the middleware in the step.

Remove removes the middleware by id. Returns error if the middleware doesn't exist.

Swap removes the middleware by id, replacing it with the new middleware. Returns the middleware removed, or error if the middleware to be removed doesn't exist.

Metadata provides storing and reading metadata values. Keys may be any comparable value type. Get and set will panic if key is not a comparable value type.

Metadata uses lazy initialization, and Set method must be called as an addressable value, or pointer. Not doing so may cause key/value pair to not be set.

Clone creates a shallow copy of Metadata entries, returning a new Metadata value with the original entries copied into it.

func (m Metadata) Get(key interface{}) interface{}

Get attempts to retrieve the value the key points to. Returns nil if the key was not found.

Panics if key type is not comparable.

Has returns whether the key exists in the metadata.

Panics if the key type is not comparable.

func (m *Metadata) Set(key, value interface{})

Set stores the value pointed to by the key. If a value already exists at that key it will be replaced with the new value.

Set method must be called as an addressable value, or pointer. If Set is not called as an addressable value or pointer, the key value pair being set may be lost.

Panics if the key type is not comparable.

type MetadataReader interface {
	Get(key interface{}) interface{}
}

MetadataReader provides an interface for reading metadata from the underlying metadata container.

Middleware provides the interface to call handlers in a chain.

type RelativePosition int

RelativePosition provides specifying the relative position of a middleware in an ordered group.

Relative position for middleware in steps.

type SerializeHandler

SerializeHandler provides the interface for the next handler the SerializeMiddleware will call in the middleware chain.

type SerializeHandlerFunc

SerializeHandlerFunc provides a wrapper around a function to be used as a serialize middleware handler.

func (SerializeHandlerFunc) HandleSerialize

HandleSerialize calls the wrapped function with the provided arguments.

type SerializeInput struct {
	Parameters interface{}
	Request    interface{}
}

SerializeInput provides the input parameters for the SerializeMiddleware to consume. SerializeMiddleware may modify the Request value before forwarding SerializeInput along to the next SerializeHandler. The Parameters member should not be modified by SerializeMiddleware, InitializeMiddleware should be responsible for modifying the provided Parameter value.

SerializeMiddleware provides the interface for middleware specific to the serialize step. Delegates to the next SerializeHandler for further processing.

SerializeMiddlewareFunc returns a SerializeMiddleware with the unique ID provided, and the func to be invoked.

type SerializeOutput struct {
	Result interface{}
}

SerializeOutput provides the result returned by the next SerializeHandler.

type SerializeStep struct {
	
}

SerializeStep provides the ordered grouping of SerializeMiddleware to be invoked on a handler.

func NewSerializeStep(newRequest func() interface{}) *SerializeStep

NewSerializeStep returns a SerializeStep ready to have middleware for initialization added to it. The newRequest func parameter is used to initialize the transport specific request for the stack SerializeStep to serialize the input parameters into.

Add injects the middleware to the relative position of the middleware group. Returns an error if the middleware already exists.

Clear removes all middleware in the step.

Get retrieves the middleware identified by id. If the middleware is not present, returns false.

func (*SerializeStep) HandleMiddleware

HandleMiddleware invokes the middleware by decorating the next handler provided. Returns the result of the middleware and handler being invoked.

Implements Middleware interface.

ID returns the unique ID of the step as a middleware.

Insert injects the middleware relative to an existing middleware ID. Returns error if the original middleware does not exist, or the middleware being added already exists.

List returns a list of the middleware in the step.

Remove removes the middleware by id. Returns error if the middleware doesn't exist.

Swap removes the middleware by id, replacing it with the new middleware. Returns the middleware removed, or error if the middleware to be removed doesn't exist.

Stack provides protocol and transport agnostic set of middleware split into distinct steps. Steps have specific transitions between them, that are managed by the individual step.

Steps are composed as middleware around the underlying handler in the following order:

Initialize -> Serialize -> Build -> Finalize -> Deserialize -> Handler

Any middleware within the chain may choose to stop and return an error or response. Since the middleware decorate the handler like a call stack, each middleware will receive the result of the next middleware in the chain. Middleware that does not need to react to an input, or result must forward along the input down the chain, or return the result back up the chain.

Initialize <- Serialize -> Build -> Finalize <- Deserialize <- Handler
func NewStack(id string, newRequestFn func() interface{}) *Stack

NewStack returns an initialize empty stack.

func (*Stack) HandleMiddleware

HandleMiddleware invokes the middleware stack decorating the next handler. Each step of stack will be invoked in order before calling the next step. With the next handler call last.

The input value must be the input parameters of the operation being performed.

Will return the result of the operation, or error.

ID returns the unique ID for the stack as a middleware.

List returns a list of all middleware in the stack by step.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4