...

Package middleware

import "github.com/aws/smithy-go/middleware"
Overview
Index

Overview ▾

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)

Index ▾

func AddSetLoggerMiddleware(stack *Stack, logger logging.Logger) error
func ClearStackValues(ctx context.Context) context.Context
func GetLogger(ctx context.Context) logging.Logger
func GetStackValue(ctx context.Context, key interface{}) interface{}
func SetLogger(ctx context.Context, logger logging.Logger) context.Context
func WithStackValue(ctx context.Context, key, value interface{}) context.Context
type BuildHandler
type BuildHandlerFunc
    func (b BuildHandlerFunc) HandleBuild(ctx context.Context, in BuildInput) (BuildOutput, Metadata, error)
type BuildInput
type BuildMiddleware
    func BuildMiddlewareFunc(id string, fn func(context.Context, BuildInput, BuildHandler) (BuildOutput, Metadata, error)) BuildMiddleware
type BuildOutput
type BuildStep
    func NewBuildStep() *BuildStep
    func (s *BuildStep) Add(m BuildMiddleware, pos RelativePosition) error
    func (s *BuildStep) Clear()
    func (s *BuildStep) Get(id string) (BuildMiddleware, bool)
    func (s *BuildStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (out interface{}, metadata Metadata, err error)
    func (s *BuildStep) ID() string
    func (s *BuildStep) Insert(m BuildMiddleware, relativeTo string, pos RelativePosition) error
    func (s *BuildStep) List() []string
    func (s *BuildStep) Remove(id string) (BuildMiddleware, error)
    func (s *BuildStep) Swap(id string, m BuildMiddleware) (BuildMiddleware, error)
type DeserializeHandler
type DeserializeHandlerFunc
    func (d DeserializeHandlerFunc) HandleDeserialize(ctx context.Context, in DeserializeInput) (DeserializeOutput, Metadata, error)
type DeserializeInput
type DeserializeMiddleware
    func DeserializeMiddlewareFunc(id string, fn func(context.Context, DeserializeInput, DeserializeHandler) (DeserializeOutput, Metadata, error)) DeserializeMiddleware
type DeserializeOutput
type DeserializeStep
    func NewDeserializeStep() *DeserializeStep
    func (s *DeserializeStep) Add(m DeserializeMiddleware, pos RelativePosition) error
    func (s *DeserializeStep) Clear()
    func (s *DeserializeStep) Get(id string) (DeserializeMiddleware, bool)
    func (s *DeserializeStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (out interface{}, metadata Metadata, err error)
    func (s *DeserializeStep) ID() string
    func (s *DeserializeStep) Insert(m DeserializeMiddleware, relativeTo string, pos RelativePosition) error
    func (s *DeserializeStep) List() []string
    func (s *DeserializeStep) Remove(id string) (DeserializeMiddleware, error)
    func (s *DeserializeStep) Swap(id string, m DeserializeMiddleware) (DeserializeMiddleware, error)
type FinalizeHandler
type FinalizeHandlerFunc
    func (f FinalizeHandlerFunc) HandleFinalize(ctx context.Context, in FinalizeInput) (FinalizeOutput, Metadata, error)
type FinalizeInput
type FinalizeMiddleware
    func FinalizeMiddlewareFunc(id string, fn func(context.Context, FinalizeInput, FinalizeHandler) (FinalizeOutput, Metadata, error)) FinalizeMiddleware
type FinalizeOutput
type FinalizeStep
    func NewFinalizeStep() *FinalizeStep
    func (s *FinalizeStep) Add(m FinalizeMiddleware, pos RelativePosition) error
    func (s *FinalizeStep) Clear()
    func (s *FinalizeStep) Get(id string) (FinalizeMiddleware, bool)
    func (s *FinalizeStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (out interface{}, metadata Metadata, err error)
    func (s *FinalizeStep) ID() string
    func (s *FinalizeStep) Insert(m FinalizeMiddleware, relativeTo string, pos RelativePosition) error
    func (s *FinalizeStep) List() []string
    func (s *FinalizeStep) Remove(id string) (FinalizeMiddleware, error)
    func (s *FinalizeStep) Swap(id string, m FinalizeMiddleware) (FinalizeMiddleware, error)
type Handler
    func DecorateHandler(h Handler, with ...Middleware) Handler
type HandlerFunc
    func (fn HandlerFunc) Handle(ctx context.Context, input interface{}) (output interface{}, metadata Metadata, err error)
type InitializeHandler
type InitializeHandlerFunc
    func (i InitializeHandlerFunc) HandleInitialize(ctx context.Context, in InitializeInput) (InitializeOutput, Metadata, error)
type InitializeInput
type InitializeMiddleware
    func InitializeMiddlewareFunc(id string, fn func(context.Context, InitializeInput, InitializeHandler) (InitializeOutput, Metadata, error)) InitializeMiddleware
type InitializeOutput
type InitializeStep
    func NewInitializeStep() *InitializeStep
    func (s *InitializeStep) Add(m InitializeMiddleware, pos RelativePosition) error
    func (s *InitializeStep) Clear()
    func (s *InitializeStep) Get(id string) (InitializeMiddleware, bool)
    func (s *InitializeStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (out interface{}, metadata Metadata, err error)
    func (s *InitializeStep) ID() string
    func (s *InitializeStep) Insert(m InitializeMiddleware, relativeTo string, pos RelativePosition) error
    func (s *InitializeStep) List() []string
    func (s *InitializeStep) Remove(id string) (InitializeMiddleware, error)
    func (s *InitializeStep) Swap(id string, m InitializeMiddleware) (InitializeMiddleware, error)
type Metadata
    func (m Metadata) Clone() Metadata
    func (m Metadata) Get(key interface{}) interface{}
    func (m Metadata) Has(key interface{}) bool
    func (m *Metadata) Set(key, value interface{})
type MetadataReader
type Middleware
type RelativePosition
type SerializeHandler
type SerializeHandlerFunc
    func (s SerializeHandlerFunc) HandleSerialize(ctx context.Context, in SerializeInput) (SerializeOutput, Metadata, error)
type SerializeInput
type SerializeMiddleware
    func SerializeMiddlewareFunc(id string, fn func(context.Context, SerializeInput, SerializeHandler) (SerializeOutput, Metadata, error)) SerializeMiddleware
type SerializeOutput
type SerializeStep
    func NewSerializeStep(newRequest func() interface{}) *SerializeStep
    func (s *SerializeStep) Add(m SerializeMiddleware, pos RelativePosition) error
    func (s *SerializeStep) Clear()
    func (s *SerializeStep) Get(id string) (SerializeMiddleware, bool)
    func (s *SerializeStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (out interface{}, metadata Metadata, err error)
    func (s *SerializeStep) ID() string
    func (s *SerializeStep) Insert(m SerializeMiddleware, relativeTo string, pos RelativePosition) error
    func (s *SerializeStep) List() []string
    func (s *SerializeStep) Remove(id string) (SerializeMiddleware, error)
    func (s *SerializeStep) Swap(id string, m SerializeMiddleware) (SerializeMiddleware, error)
type Stack
    func NewStack(id string, newRequestFn func() interface{}) *Stack
    func (s *Stack) HandleMiddleware(ctx context.Context, input interface{}, next Handler) (output interface{}, metadata Metadata, err error)
    func (s *Stack) ID() string
    func (s *Stack) List() []string
    func (s *Stack) String() string

Package files

doc.go logging.go metadata.go middleware.go ordered_group.go stack.go stack_values.go step_build.go step_deserialize.go step_finalize.go step_initialize.go step_serialize.go

func AddSetLoggerMiddleware

func AddSetLoggerMiddleware(stack *Stack, logger logging.Logger) error

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

func ClearStackValues

func ClearStackValues(ctx context.Context) context.Context

ClearStackValues returns a context without any stack values.

func GetLogger

func GetLogger(ctx context.Context) logging.Logger

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.

func GetStackValue

func GetStackValue(ctx context.Context, key interface{}) interface{}

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

func SetLogger

func SetLogger(ctx context.Context, logger logging.Logger) context.Context

SetLogger sets the provided logger value on the provided ctx.

func WithStackValue

func WithStackValue(ctx context.Context, key, value interface{}) context.Context

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 BuildHandler interface {
    HandleBuild(ctx context.Context, in BuildInput) (
        out BuildOutput, metadata Metadata, err error,
    )
}

type BuildHandlerFunc

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

type BuildHandlerFunc func(context.Context, BuildInput) (BuildOutput, Metadata, error)

func (BuildHandlerFunc) HandleBuild

func (b BuildHandlerFunc) HandleBuild(ctx context.Context, in BuildInput) (BuildOutput, Metadata, error)

HandleBuild invokes the wrapped function with the provided arguments.

type BuildInput

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.

type BuildInput struct {
    Request interface{}
}

type BuildMiddleware

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

type BuildMiddleware interface {
    // Unique ID for the middleware in theBuildStep. The step does not allow
    // duplicate IDs.
    ID() string

    // Invokes the middleware behavior which must delegate to the next handler
    // for the middleware chain to continue. The method must return a result or
    // error to its caller.
    HandleBuild(ctx context.Context, in BuildInput, next BuildHandler) (
        out BuildOutput, metadata Metadata, err error,
    )
}

func BuildMiddlewareFunc

func BuildMiddlewareFunc(id string, fn func(context.Context, BuildInput, BuildHandler) (BuildOutput, Metadata, error)) BuildMiddleware

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

type BuildOutput

BuildOutput provides the result returned by the next BuildHandler.

type BuildOutput struct {
    Result interface{}
}

type BuildStep

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

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

func NewBuildStep

func NewBuildStep() *BuildStep

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

func (*BuildStep) Add

func (s *BuildStep) Add(m BuildMiddleware, pos RelativePosition) error

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

func (*BuildStep) Clear

func (s *BuildStep) Clear()

Clear removes all middleware in the step.

func (*BuildStep) Get

func (s *BuildStep) Get(id string) (BuildMiddleware, bool)

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

func (*BuildStep) HandleMiddleware

func (s *BuildStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (
    out interface{}, metadata Metadata, err error,
)

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

Implements Middleware interface.

func (*BuildStep) ID

func (s *BuildStep) ID() string

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

func (*BuildStep) Insert

func (s *BuildStep) Insert(m BuildMiddleware, relativeTo string, pos RelativePosition) error

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.

func (*BuildStep) List

func (s *BuildStep) List() []string

List returns a list of the middleware in the step.

func (*BuildStep) Remove

func (s *BuildStep) Remove(id string) (BuildMiddleware, error)

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

func (*BuildStep) Swap

func (s *BuildStep) Swap(id string, m BuildMiddleware) (BuildMiddleware, error)

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 DeserializeHandler interface {
    HandleDeserialize(ctx context.Context, in DeserializeInput) (
        out DeserializeOutput, metadata Metadata, err error,
    )
}

type DeserializeHandlerFunc

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

type DeserializeHandlerFunc func(context.Context, DeserializeInput) (DeserializeOutput, Metadata, error)

func (DeserializeHandlerFunc) HandleDeserialize

func (d DeserializeHandlerFunc) HandleDeserialize(ctx context.Context, in DeserializeInput) (DeserializeOutput, Metadata, error)

HandleDeserialize invokes the wrapped function with the given arguments.

type DeserializeInput

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.

type DeserializeInput struct {
    Request interface{}
}

type DeserializeMiddleware

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

type DeserializeMiddleware interface {
    // ID returns a unique ID for the middleware in the DeserializeStep. The step does not
    // allow duplicate IDs.
    ID() string

    // HandleDeserialize invokes the middleware behavior which must delegate to the next handler
    // for the middleware chain to continue. The method must return a result or
    // error to its caller.
    HandleDeserialize(ctx context.Context, in DeserializeInput, next DeserializeHandler) (
        out DeserializeOutput, metadata Metadata, err error,
    )
}

func DeserializeMiddlewareFunc

func DeserializeMiddlewareFunc(id string, fn func(context.Context, DeserializeInput, DeserializeHandler) (DeserializeOutput, Metadata, error)) DeserializeMiddleware

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

type DeserializeOutput

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 DeserializeOutput struct {
    RawResponse interface{}
    Result      interface{}
}

type DeserializeStep

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

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

func NewDeserializeStep

func NewDeserializeStep() *DeserializeStep

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

func (*DeserializeStep) Add

func (s *DeserializeStep) Add(m DeserializeMiddleware, pos RelativePosition) error

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

func (*DeserializeStep) Clear

func (s *DeserializeStep) Clear()

Clear removes all middleware in the step.

func (*DeserializeStep) Get

func (s *DeserializeStep) Get(id string) (DeserializeMiddleware, bool)

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

func (*DeserializeStep) HandleMiddleware

func (s *DeserializeStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (
    out interface{}, metadata Metadata, err error,
)

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

Implements Middleware interface.

func (*DeserializeStep) ID

func (s *DeserializeStep) ID() string

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

func (*DeserializeStep) Insert

func (s *DeserializeStep) Insert(m DeserializeMiddleware, relativeTo string, pos RelativePosition) error

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.

func (*DeserializeStep) List

func (s *DeserializeStep) List() []string

List returns a list of the middleware in the step.

func (*DeserializeStep) Remove

func (s *DeserializeStep) Remove(id string) (DeserializeMiddleware, error)

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

func (*DeserializeStep) Swap

func (s *DeserializeStep) Swap(id string, m DeserializeMiddleware) (DeserializeMiddleware, error)

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 FinalizeHandler interface {
    HandleFinalize(ctx context.Context, in FinalizeInput) (
        out FinalizeOutput, metadata Metadata, err error,
    )
}

type FinalizeHandlerFunc

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

type FinalizeHandlerFunc func(context.Context, FinalizeInput) (FinalizeOutput, Metadata, error)

func (FinalizeHandlerFunc) HandleFinalize

func (f FinalizeHandlerFunc) HandleFinalize(ctx context.Context, in FinalizeInput) (FinalizeOutput, Metadata, error)

HandleFinalize invokes the wrapped function with the given arguments.

type FinalizeInput

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.

type FinalizeInput struct {
    Request interface{}
}

type FinalizeMiddleware

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

type FinalizeMiddleware interface {
    // ID returns a unique ID for the middleware in the FinalizeStep. The step does not
    // allow duplicate IDs.
    ID() string

    // HandleFinalize invokes the middleware behavior which must delegate to the next handler
    // for the middleware chain to continue. The method must return a result or
    // error to its caller.
    HandleFinalize(ctx context.Context, in FinalizeInput, next FinalizeHandler) (
        out FinalizeOutput, metadata Metadata, err error,
    )
}

func FinalizeMiddlewareFunc

func FinalizeMiddlewareFunc(id string, fn func(context.Context, FinalizeInput, FinalizeHandler) (FinalizeOutput, Metadata, error)) FinalizeMiddleware

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

type FinalizeOutput

FinalizeOutput provides the result returned by the next FinalizeHandler.

type FinalizeOutput struct {
    Result interface{}
}

type FinalizeStep

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

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

func NewFinalizeStep

func NewFinalizeStep() *FinalizeStep

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

func (*FinalizeStep) Add

func (s *FinalizeStep) Add(m FinalizeMiddleware, pos RelativePosition) error

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

func (*FinalizeStep) Clear

func (s *FinalizeStep) Clear()

Clear removes all middleware in the step.

func (*FinalizeStep) Get

func (s *FinalizeStep) Get(id string) (FinalizeMiddleware, bool)

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

func (*FinalizeStep) HandleMiddleware

func (s *FinalizeStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (
    out interface{}, metadata Metadata, err error,
)

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

Implements Middleware interface.

func (*FinalizeStep) ID

func (s *FinalizeStep) ID() string

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

func (*FinalizeStep) Insert

func (s *FinalizeStep) Insert(m FinalizeMiddleware, relativeTo string, pos RelativePosition) error

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.

func (*FinalizeStep) List

func (s *FinalizeStep) List() []string

List returns a list of the middleware in the step.

func (*FinalizeStep) Remove

func (s *FinalizeStep) Remove(id string) (FinalizeMiddleware, error)

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

func (*FinalizeStep) Swap

func (s *FinalizeStep) Swap(id string, m FinalizeMiddleware) (FinalizeMiddleware, error)

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.

type Handler interface {
    // Handle performs logic to obtain an output for the given input. Handler
    // should be decorated with middleware to perform input specific behavior.
    Handle(ctx context.Context, input interface{}) (
        output interface{}, metadata Metadata, err error,
    )
}

func DecorateHandler

func DecorateHandler(h Handler, with ...Middleware) Handler

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.

type HandlerFunc func(ctx context.Context, input interface{}) (
    output interface{}, metadata Metadata, err error,
)

func (HandlerFunc) Handle

func (fn HandlerFunc) Handle(ctx context.Context, input interface{}) (
    output interface{}, metadata Metadata, err error,
)

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 InitializeHandler interface {
    HandleInitialize(ctx context.Context, in InitializeInput) (
        out InitializeOutput, metadata Metadata, err error,
    )
}

type InitializeHandlerFunc

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

type InitializeHandlerFunc func(context.Context, InitializeInput) (InitializeOutput, Metadata, error)

func (InitializeHandlerFunc) HandleInitialize

func (i InitializeHandlerFunc) HandleInitialize(ctx context.Context, in InitializeInput) (InitializeOutput, Metadata, error)

HandleInitialize calls the wrapped function with the provided arguments.

type InitializeInput

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

type InitializeInput struct {
    Parameters interface{}
}

type InitializeMiddleware

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

type InitializeMiddleware interface {
    // ID returns a unique ID for the middleware in the InitializeStep. The step does not
    // allow duplicate IDs.
    ID() string

    // HandleInitialize invokes the middleware behavior which must delegate to the next handler
    // for the middleware chain to continue. The method must return a result or
    // error to its caller.
    HandleInitialize(ctx context.Context, in InitializeInput, next InitializeHandler) (
        out InitializeOutput, metadata Metadata, err error,
    )
}

func InitializeMiddlewareFunc

func InitializeMiddlewareFunc(id string, fn func(context.Context, InitializeInput, InitializeHandler) (InitializeOutput, Metadata, error)) InitializeMiddleware

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

type InitializeOutput

InitializeOutput provides the result returned by the next InitializeHandler.

type InitializeOutput struct {
    Result interface{}
}

type InitializeStep

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

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

func NewInitializeStep

func NewInitializeStep() *InitializeStep

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

func (*InitializeStep) Add

func (s *InitializeStep) Add(m InitializeMiddleware, pos RelativePosition) error

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

func (*InitializeStep) Clear

func (s *InitializeStep) Clear()

Clear removes all middleware in the step.

func (*InitializeStep) Get

func (s *InitializeStep) Get(id string) (InitializeMiddleware, bool)

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

func (*InitializeStep) HandleMiddleware

func (s *InitializeStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (
    out interface{}, metadata Metadata, err error,
)

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

Implements Middleware interface.

func (*InitializeStep) ID

func (s *InitializeStep) ID() string

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

func (*InitializeStep) Insert

func (s *InitializeStep) Insert(m InitializeMiddleware, relativeTo string, pos RelativePosition) error

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.

func (*InitializeStep) List

func (s *InitializeStep) List() []string

List returns a list of the middleware in the step.

func (*InitializeStep) Remove

func (s *InitializeStep) Remove(id string) (InitializeMiddleware, error)

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

func (*InitializeStep) Swap

func (s *InitializeStep) Swap(id string, m InitializeMiddleware) (InitializeMiddleware, error)

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 Metadata

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.

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

func (Metadata) Clone

func (m Metadata) Clone() Metadata

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

func (Metadata) Get

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.

func (Metadata) Has

func (m Metadata) Has(key interface{}) bool

Has returns whether the key exists in the metadata.

Panics if the key type is not comparable.

func (*Metadata) Set

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

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

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

type Middleware

Middleware provides the interface to call handlers in a chain.

type Middleware interface {
    // ID provides a unique identifier for the middleware.
    ID() string

    // Performs the middleware's handling of the input, returning the output,
    // or error. The middleware can invoke the next Handler if handling should
    // continue.
    HandleMiddleware(ctx context.Context, input interface{}, next Handler) (
        output interface{}, metadata Metadata, err error,
    )
}

type RelativePosition

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

type RelativePosition int

Relative position for middleware in steps.

const (
    After RelativePosition = iota
    Before
)

type SerializeHandler

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

type SerializeHandler interface {
    HandleSerialize(ctx context.Context, in SerializeInput) (
        out SerializeOutput, metadata Metadata, err error,
    )
}

type SerializeHandlerFunc

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

type SerializeHandlerFunc func(context.Context, SerializeInput) (SerializeOutput, Metadata, error)

func (SerializeHandlerFunc) HandleSerialize

func (s SerializeHandlerFunc) HandleSerialize(ctx context.Context, in SerializeInput) (SerializeOutput, Metadata, error)

HandleSerialize calls the wrapped function with the provided arguments.

type SerializeInput

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.

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

type SerializeMiddleware

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

type SerializeMiddleware interface {
    // ID returns a unique ID for the middleware in the SerializeStep. The step does not
    // allow duplicate IDs.
    ID() string

    // HandleSerialize invokes the middleware behavior which must delegate to the next handler
    // for the middleware chain to continue. The method must return a result or
    // error to its caller.
    HandleSerialize(ctx context.Context, in SerializeInput, next SerializeHandler) (
        out SerializeOutput, metadata Metadata, err error,
    )
}

func SerializeMiddlewareFunc

func SerializeMiddlewareFunc(id string, fn func(context.Context, SerializeInput, SerializeHandler) (SerializeOutput, Metadata, error)) SerializeMiddleware

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

type SerializeOutput

SerializeOutput provides the result returned by the next SerializeHandler.

type SerializeOutput struct {
    Result interface{}
}

type SerializeStep

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

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

func NewSerializeStep

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.

func (*SerializeStep) Add

func (s *SerializeStep) Add(m SerializeMiddleware, pos RelativePosition) error

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

func (*SerializeStep) Clear

func (s *SerializeStep) Clear()

Clear removes all middleware in the step.

func (*SerializeStep) Get

func (s *SerializeStep) Get(id string) (SerializeMiddleware, bool)

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

func (*SerializeStep) HandleMiddleware

func (s *SerializeStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (
    out interface{}, metadata Metadata, err error,
)

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

Implements Middleware interface.

func (*SerializeStep) ID

func (s *SerializeStep) ID() string

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

func (*SerializeStep) Insert

func (s *SerializeStep) Insert(m SerializeMiddleware, relativeTo string, pos RelativePosition) error

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.

func (*SerializeStep) List

func (s *SerializeStep) List() []string

List returns a list of the middleware in the step.

func (*SerializeStep) Remove

func (s *SerializeStep) Remove(id string) (SerializeMiddleware, error)

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

func (*SerializeStep) Swap

func (s *SerializeStep) Swap(id string, m SerializeMiddleware) (SerializeMiddleware, error)

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 Stack

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
type Stack struct {
    // Initialize prepares the input, and sets any default parameters as
    // needed, (e.g. idempotency token, and presigned URLs).
    //
    // Takes Input Parameters, and returns result or error.
    //
    // Receives result or error from Serialize step.
    Initialize *InitializeStep

    // Serialize serializes the prepared input into a data structure that can be consumed
    // by the target transport's message, (e.g. REST-JSON serialization)
    //
    // Converts Input Parameters into a Request, and returns the result or error.
    //
    // Receives result or error from Build step.
    Serialize *SerializeStep

    // 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.
    //
    // Takes Request, and returns result or error.
    //
    // Receives result or error from Finalize step.
    Build *BuildStep

    // 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)
    //
    // Takes Request, and returns result or error.
    //
    // Receives result or error from Deserialize step.
    Finalize *FinalizeStep

    // 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.
    //
    // Should only forward Request to underlying handler.
    //
    // Takes Request, and returns result or error.
    //
    // Receives raw response, or error from underlying handler.
    Deserialize *DeserializeStep
    // contains filtered or unexported fields
}

func NewStack

func NewStack(id string, newRequestFn func() interface{}) *Stack

NewStack returns an initialize empty stack.

func (*Stack) HandleMiddleware

func (s *Stack) HandleMiddleware(ctx context.Context, input interface{}, next Handler) (
    output interface{}, metadata Metadata, err error,
)

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.

func (*Stack) ID

func (s *Stack) ID() string

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

func (*Stack) List

func (s *Stack) List() []string

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

func (*Stack) String

func (s *Stack) String() string