This commit is contained in:
2026-02-19 10:07:43 +00:00
parent 007438e372
commit 6e637ecf77
1763 changed files with 60820 additions and 279516 deletions

View File

@@ -23,12 +23,14 @@ type orderedIDs struct {
items map[string]ider
}
const baseOrderedItems = 5
// selected based on the general upper bound of # of middlewares in each step
// in the downstream aws-sdk-go-v2
const baseOrderedItems = 8
func newOrderedIDs() *orderedIDs {
func newOrderedIDs(cap int) *orderedIDs {
return &orderedIDs{
order: newRelativeOrder(),
items: make(map[string]ider, baseOrderedItems),
order: newRelativeOrder(cap),
items: make(map[string]ider, cap),
}
}
@@ -141,9 +143,9 @@ type relativeOrder struct {
order []string
}
func newRelativeOrder() *relativeOrder {
func newRelativeOrder(cap int) *relativeOrder {
return &relativeOrder{
order: make([]string, 0, baseOrderedItems),
order: make([]string, 0, cap),
}
}

View File

@@ -1,7 +1,9 @@
// Code generated by smithy-go/middleware/generate.go DO NOT EDIT.
package middleware
import (
"context"
"fmt"
)
// BuildInput provides the input parameters for the BuildMiddleware to consume.
@@ -25,14 +27,14 @@ type BuildHandler interface {
}
// BuildMiddleware provides the interface for middleware specific to the
// serialize step. Delegates to the next BuildHandler for further
// build 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 returns a unique ID for the middleware in the BuildStep. The step does not
// allow duplicate IDs.
ID() string
// Invokes the middleware behavior which must delegate to the next handler
// HandleBuild 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) (
@@ -54,7 +56,9 @@ type buildMiddlewareFunc struct {
id string
// Middleware function to be called.
fn func(context.Context, BuildInput, BuildHandler) (BuildOutput, Metadata, error)
fn func(context.Context, BuildInput, BuildHandler) (
BuildOutput, Metadata, error,
)
}
// ID returns the unique ID for the middleware.
@@ -69,23 +73,22 @@ func (s buildMiddlewareFunc) HandleBuild(ctx context.Context, in BuildInput, nex
var _ BuildMiddleware = (buildMiddlewareFunc{})
// BuildStep provides the ordered grouping of BuildMiddleware to be invoked on
// a handler.
// BuildStep provides the ordered grouping of BuildMiddleware to be
// invoked on a handler.
type BuildStep struct {
ids *orderedIDs
head *decoratedBuildHandler
tail *decoratedBuildHandler
}
// NewBuildStep returns a BuildStep ready to have middleware for
// initialization added to it.
// NewBuildStep returns an BuildStep ready to have middleware for
// build added to it.
func NewBuildStep() *BuildStep {
return &BuildStep{
ids: newOrderedIDs(),
}
return &BuildStep{}
}
var _ Middleware = (*BuildStep)(nil)
// ID returns the unique name of the step as a middleware.
// ID returns the unique ID of the step as a middleware.
func (s *BuildStep) ID() string {
return "Build stack step"
}
@@ -97,77 +100,161 @@ func (s *BuildStep) ID() string {
func (s *BuildStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (
out interface{}, metadata Metadata, err error,
) {
order := s.ids.GetOrder()
var h BuildHandler = buildWrapHandler{Next: next}
for i := len(order) - 1; i >= 0; i-- {
h = decoratedBuildHandler{
Next: h,
With: order[i].(BuildMiddleware),
}
}
sIn := BuildInput{
Request: in,
}
res, metadata, err := h.HandleBuild(ctx, sIn)
wh := &buildWrapHandler{next}
if s.head == nil {
res, metadata, err := wh.HandleBuild(ctx, sIn)
return res.Result, metadata, err
}
s.tail.Next = wh
res, metadata, err := s.head.HandleBuild(ctx, sIn)
return res.Result, metadata, err
}
// Get retrieves the middleware identified by id. If the middleware is not present, returns false.
func (s *BuildStep) Get(id string) (BuildMiddleware, bool) {
get, ok := s.ids.Get(id)
if !ok {
found, _ := s.get(id)
if found == nil {
return nil, false
}
return get.(BuildMiddleware), ok
return found.With, true
}
// Add injects the middleware to the relative position of the middleware group.
// Returns an error if the middleware already exists.
//
// Add never returns an error. It used to for duplicate phases but this
// behavior has since been removed as part of a performance optimization. The
// return value from Add can be ignored.
func (s *BuildStep) Add(m BuildMiddleware, pos RelativePosition) error {
return s.ids.Add(m, pos)
if s.head == nil {
s.head = &decoratedBuildHandler{nil, m}
s.tail = s.head
return nil
}
if pos == Before {
s.head = &decoratedBuildHandler{s.head, m}
} else {
tail := &decoratedBuildHandler{nil, m}
s.tail.Next = tail
s.tail = tail
}
return nil
}
// Insert injects the middleware relative to an existing middleware id.
// Returns an error if the original middleware does not exist, or the 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.
func (s *BuildStep) Insert(m BuildMiddleware, relativeTo string, pos RelativePosition) error {
return s.ids.Insert(m, relativeTo, pos)
found, prev := s.get(relativeTo)
if found == nil {
return fmt.Errorf("not found: %s", m.ID())
}
if pos == Before {
if prev == nil { // at the front
s.head = &decoratedBuildHandler{s.head, m}
} else { // somewhere in the middle
prev.Next = &decoratedBuildHandler{found, m}
}
} else {
if found.Next == nil { // at the end
tail := &decoratedBuildHandler{nil, m}
s.tail.Next = tail
s.tail = tail
} else { // somewhere in the middle
found.Next = &decoratedBuildHandler{found.Next, m}
}
}
return nil
}
// 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
// Returns the middleware removed, or error if the middleware to be removed
// doesn't exist.
func (s *BuildStep) Swap(id string, m BuildMiddleware) (BuildMiddleware, error) {
removed, err := s.ids.Swap(id, m)
if err != nil {
return nil, err
found, _ := s.get(id)
if found == nil {
return nil, fmt.Errorf("not found: %s", m.ID())
}
return removed.(BuildMiddleware), nil
swapped := found.With
found.With = m
return swapped, nil
}
// Remove removes the middleware by id. Returns error if the middleware
// doesn't exist.
func (s *BuildStep) Remove(id string) (BuildMiddleware, error) {
removed, err := s.ids.Remove(id)
if err != nil {
return nil, err
found, prev := s.get(id)
if found == nil {
return nil, fmt.Errorf("not found: %s", id)
}
return removed.(BuildMiddleware), nil
if s.head == s.tail { // it's the only one
s.head = nil
s.tail = nil
} else if found == s.head { // at the front
s.head = s.head.Next.(*decoratedBuildHandler)
} else if found == s.tail { // at the end
prev.Next = nil
s.tail = prev
} else {
prev.Next = found.Next // somewhere in the middle
}
return found.With, nil
}
// List returns a list of the middleware in the step.
func (s *BuildStep) List() []string {
return s.ids.List()
var ids []string
for h := s.head; h != nil; {
ids = append(ids, h.With.ID())
if h.Next == nil {
break
}
// once executed, tail.Next of the list will be set to an
// *buildWrapHandler, make sure to check for that
if hnext, ok := h.Next.(*decoratedBuildHandler); ok {
h = hnext
} else {
break
}
}
return ids
}
// Clear removes all middleware in the step.
func (s *BuildStep) Clear() {
s.ids.Clear()
s.head = nil
s.tail = nil
}
func (s *BuildStep) get(id string) (found, prev *decoratedBuildHandler) {
for h := s.head; h != nil; {
if h.With.ID() == id {
found = h
return
}
prev = h
if h.Next == nil {
return
}
// once executed, tail.Next of the list will be set to an
// *buildWrapHandler
h, _ = h.Next.(*decoratedBuildHandler)
}
return
}
type buildWrapHandler struct {
@@ -176,7 +263,7 @@ type buildWrapHandler struct {
var _ BuildHandler = (*buildWrapHandler)(nil)
// Implements BuildHandler, converts types and delegates to underlying
// HandleBuild implements BuildHandler, converts types and delegates to underlying
// generic handler.
func (w buildWrapHandler) HandleBuild(ctx context.Context, in BuildInput) (
out BuildOutput, metadata Metadata, err error,
@@ -200,12 +287,12 @@ func (h decoratedBuildHandler) HandleBuild(ctx context.Context, in BuildInput) (
return h.With.HandleBuild(ctx, in, h.Next)
}
// BuildHandlerFunc provides a wrapper around a function to be used as a build middleware handler.
// BuildHandlerFunc provides a wrapper around a function to be used as buildMiddleware.
type BuildHandlerFunc func(context.Context, BuildInput) (BuildOutput, Metadata, error)
// HandleBuild invokes the wrapped function with the provided arguments.
func (b BuildHandlerFunc) HandleBuild(ctx context.Context, in BuildInput) (BuildOutput, Metadata, error) {
return b(ctx, in)
// HandleBuild calls the wrapped function with the provided arguments.
func (f BuildHandlerFunc) HandleBuild(ctx context.Context, in BuildInput) (BuildOutput, Metadata, error) {
return f(ctx, in)
}
var _ BuildHandler = BuildHandlerFunc(nil)

View File

@@ -1,7 +1,9 @@
// Code generated by smithy-go/middleware/generate.go DO NOT EDIT.
package middleware
import (
"context"
"fmt"
)
// DeserializeInput provides the input parameters for the DeserializeInput to
@@ -11,10 +13,7 @@ type DeserializeInput struct {
Request 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.
// DeserializeOutput provides the result returned by the next DeserializeHandler.
type DeserializeOutput struct {
RawResponse interface{}
Result interface{}
@@ -29,7 +28,7 @@ type DeserializeHandler interface {
}
// DeserializeMiddleware provides the interface for middleware specific to the
// serialize step. Delegates to the next DeserializeHandler for further
// deserialize 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
@@ -44,8 +43,8 @@ type DeserializeMiddleware interface {
)
}
// DeserializeMiddlewareFunc returns a DeserializeMiddleware with the unique ID
// provided, and the func to be invoked.
// DeserializeMiddlewareFunc returns a DeserializeMiddleware with the unique ID provided,
// and the func to be invoked.
func DeserializeMiddlewareFunc(id string, fn func(context.Context, DeserializeInput, DeserializeHandler) (DeserializeOutput, Metadata, error)) DeserializeMiddleware {
return deserializeMiddlewareFunc{
id: id,
@@ -78,15 +77,14 @@ var _ DeserializeMiddleware = (deserializeMiddlewareFunc{})
// DeserializeStep provides the ordered grouping of DeserializeMiddleware to be
// invoked on a handler.
type DeserializeStep struct {
ids *orderedIDs
head *decoratedDeserializeHandler
tail *decoratedDeserializeHandler
}
// NewDeserializeStep returns a DeserializeStep ready to have middleware for
// initialization added to it.
// NewDeserializeStep returns an DeserializeStep ready to have middleware for
// deserialize added to it.
func NewDeserializeStep() *DeserializeStep {
return &DeserializeStep{
ids: newOrderedIDs(),
}
return &DeserializeStep{}
}
var _ Middleware = (*DeserializeStep)(nil)
@@ -103,77 +101,161 @@ func (s *DeserializeStep) ID() string {
func (s *DeserializeStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (
out interface{}, metadata Metadata, err error,
) {
order := s.ids.GetOrder()
var h DeserializeHandler = deserializeWrapHandler{Next: next}
for i := len(order) - 1; i >= 0; i-- {
h = decoratedDeserializeHandler{
Next: h,
With: order[i].(DeserializeMiddleware),
}
}
sIn := DeserializeInput{
Request: in,
}
res, metadata, err := h.HandleDeserialize(ctx, sIn)
wh := &deserializeWrapHandler{next}
if s.head == nil {
res, metadata, err := wh.HandleDeserialize(ctx, sIn)
return res.Result, metadata, err
}
s.tail.Next = wh
res, metadata, err := s.head.HandleDeserialize(ctx, sIn)
return res.Result, metadata, err
}
// Get retrieves the middleware identified by id. If the middleware is not present, returns false.
func (s *DeserializeStep) Get(id string) (DeserializeMiddleware, bool) {
get, ok := s.ids.Get(id)
if !ok {
found, _ := s.get(id)
if found == nil {
return nil, false
}
return get.(DeserializeMiddleware), ok
return found.With, true
}
// Add injects the middleware to the relative position of the middleware group.
// Returns an error if the middleware already exists.
//
// Add never returns an error. It used to for duplicate phases but this
// behavior has since been removed as part of a performance optimization. The
// return value from Add can be ignored.
func (s *DeserializeStep) Add(m DeserializeMiddleware, pos RelativePosition) error {
return s.ids.Add(m, pos)
if s.head == nil {
s.head = &decoratedDeserializeHandler{nil, m}
s.tail = s.head
return nil
}
if pos == Before {
s.head = &decoratedDeserializeHandler{s.head, m}
} else {
tail := &decoratedDeserializeHandler{nil, m}
s.tail.Next = tail
s.tail = tail
}
return nil
}
// 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 (s *DeserializeStep) Insert(m DeserializeMiddleware, relativeTo string, pos RelativePosition) error {
return s.ids.Insert(m, relativeTo, pos)
found, prev := s.get(relativeTo)
if found == nil {
return fmt.Errorf("not found: %s", m.ID())
}
if pos == Before {
if prev == nil { // at the front
s.head = &decoratedDeserializeHandler{s.head, m}
} else { // somewhere in the middle
prev.Next = &decoratedDeserializeHandler{found, m}
}
} else {
if found.Next == nil { // at the end
tail := &decoratedDeserializeHandler{nil, m}
s.tail.Next = tail
s.tail = tail
} else { // somewhere in the middle
found.Next = &decoratedDeserializeHandler{found.Next, m}
}
}
return nil
}
// 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.
func (s *DeserializeStep) Swap(id string, m DeserializeMiddleware) (DeserializeMiddleware, error) {
removed, err := s.ids.Swap(id, m)
if err != nil {
return nil, err
found, _ := s.get(id)
if found == nil {
return nil, fmt.Errorf("not found: %s", m.ID())
}
return removed.(DeserializeMiddleware), nil
swapped := found.With
found.With = m
return swapped, nil
}
// Remove removes the middleware by id. Returns error if the middleware
// doesn't exist.
func (s *DeserializeStep) Remove(id string) (DeserializeMiddleware, error) {
removed, err := s.ids.Remove(id)
if err != nil {
return nil, err
found, prev := s.get(id)
if found == nil {
return nil, fmt.Errorf("not found: %s", id)
}
return removed.(DeserializeMiddleware), nil
if s.head == s.tail { // it's the only one
s.head = nil
s.tail = nil
} else if found == s.head { // at the front
s.head = s.head.Next.(*decoratedDeserializeHandler)
} else if found == s.tail { // at the end
prev.Next = nil
s.tail = prev
} else {
prev.Next = found.Next // somewhere in the middle
}
return found.With, nil
}
// List returns a list of the middleware in the step.
func (s *DeserializeStep) List() []string {
return s.ids.List()
var ids []string
for h := s.head; h != nil; {
ids = append(ids, h.With.ID())
if h.Next == nil {
break
}
// once executed, tail.Next of the list will be set to an
// *deserializeWrapHandler, make sure to check for that
if hnext, ok := h.Next.(*decoratedDeserializeHandler); ok {
h = hnext
} else {
break
}
}
return ids
}
// Clear removes all middleware in the step.
func (s *DeserializeStep) Clear() {
s.ids.Clear()
s.head = nil
s.tail = nil
}
func (s *DeserializeStep) get(id string) (found, prev *decoratedDeserializeHandler) {
for h := s.head; h != nil; {
if h.With.ID() == id {
found = h
return
}
prev = h
if h.Next == nil {
return
}
// once executed, tail.Next of the list will be set to an
// *deserializeWrapHandler
h, _ = h.Next.(*decoratedDeserializeHandler)
}
return
}
type deserializeWrapHandler struct {
@@ -187,9 +269,10 @@ var _ DeserializeHandler = (*deserializeWrapHandler)(nil)
func (w deserializeWrapHandler) HandleDeserialize(ctx context.Context, in DeserializeInput) (
out DeserializeOutput, metadata Metadata, err error,
) {
resp, metadata, err := w.Next.Handle(ctx, in.Request)
res, metadata, err := w.Next.Handle(ctx, in.Request)
return DeserializeOutput{
RawResponse: resp,
RawResponse: res,
Result: nil,
}, metadata, err
}
@@ -206,12 +289,12 @@ func (h decoratedDeserializeHandler) HandleDeserialize(ctx context.Context, in D
return h.With.HandleDeserialize(ctx, in, h.Next)
}
// DeserializeHandlerFunc provides a wrapper around a function to be used as a deserialize middleware handler.
// DeserializeHandlerFunc provides a wrapper around a function to be used as deserializeMiddleware.
type DeserializeHandlerFunc func(context.Context, DeserializeInput) (DeserializeOutput, Metadata, error)
// HandleDeserialize invokes the wrapped function with the given arguments.
func (d DeserializeHandlerFunc) HandleDeserialize(ctx context.Context, in DeserializeInput) (DeserializeOutput, Metadata, error) {
return d(ctx, in)
// HandleDeserialize calls the wrapped function with the provided arguments.
func (f DeserializeHandlerFunc) HandleDeserialize(ctx context.Context, in DeserializeInput) (DeserializeOutput, Metadata, error) {
return f(ctx, in)
}
var _ DeserializeHandler = DeserializeHandlerFunc(nil)

View File

@@ -1,6 +1,10 @@
// Code generated by smithy-go/middleware/generate.go DO NOT EDIT.
package middleware
import "context"
import (
"context"
"fmt"
)
// FinalizeInput provides the input parameters for the FinalizeMiddleware to
// consume. FinalizeMiddleware may modify the Request value before forwarding
@@ -23,7 +27,7 @@ type FinalizeHandler interface {
}
// FinalizeMiddleware provides the interface for middleware specific to the
// serialize step. Delegates to the next FinalizeHandler for further
// finalize 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
@@ -38,8 +42,8 @@ type FinalizeMiddleware interface {
)
}
// FinalizeMiddlewareFunc returns a FinalizeMiddleware with the unique ID
// provided, and the func to be invoked.
// FinalizeMiddlewareFunc returns a FinalizeMiddleware with the unique ID provided,
// and the func to be invoked.
func FinalizeMiddlewareFunc(id string, fn func(context.Context, FinalizeInput, FinalizeHandler) (FinalizeOutput, Metadata, error)) FinalizeMiddleware {
return finalizeMiddlewareFunc{
id: id,
@@ -72,20 +76,19 @@ var _ FinalizeMiddleware = (finalizeMiddlewareFunc{})
// FinalizeStep provides the ordered grouping of FinalizeMiddleware to be
// invoked on a handler.
type FinalizeStep struct {
ids *orderedIDs
head *decoratedFinalizeHandler
tail *decoratedFinalizeHandler
}
// NewFinalizeStep returns a FinalizeStep ready to have middleware for
// initialization added to it.
// NewFinalizeStep returns an FinalizeStep ready to have middleware for
// finalize added to it.
func NewFinalizeStep() *FinalizeStep {
return &FinalizeStep{
ids: newOrderedIDs(),
}
return &FinalizeStep{}
}
var _ Middleware = (*FinalizeStep)(nil)
// ID returns the unique id of the step as a middleware.
// ID returns the unique ID of the step as a middleware.
func (s *FinalizeStep) ID() string {
return "Finalize stack step"
}
@@ -97,77 +100,161 @@ func (s *FinalizeStep) ID() string {
func (s *FinalizeStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (
out interface{}, metadata Metadata, err error,
) {
order := s.ids.GetOrder()
var h FinalizeHandler = finalizeWrapHandler{Next: next}
for i := len(order) - 1; i >= 0; i-- {
h = decoratedFinalizeHandler{
Next: h,
With: order[i].(FinalizeMiddleware),
}
}
sIn := FinalizeInput{
Request: in,
}
res, metadata, err := h.HandleFinalize(ctx, sIn)
wh := &finalizeWrapHandler{next}
if s.head == nil {
res, metadata, err := wh.HandleFinalize(ctx, sIn)
return res.Result, metadata, err
}
s.tail.Next = wh
res, metadata, err := s.head.HandleFinalize(ctx, sIn)
return res.Result, metadata, err
}
// Get retrieves the middleware identified by id. If the middleware is not present, returns false.
func (s *FinalizeStep) Get(id string) (FinalizeMiddleware, bool) {
get, ok := s.ids.Get(id)
if !ok {
found, _ := s.get(id)
if found == nil {
return nil, false
}
return get.(FinalizeMiddleware), ok
return found.With, true
}
// Add injects the middleware to the relative position of the middleware group.
// Returns an error if the middleware already exists.
//
// Add never returns an error. It used to for duplicate phases but this
// behavior has since been removed as part of a performance optimization. The
// return value from Add can be ignored.
func (s *FinalizeStep) Add(m FinalizeMiddleware, pos RelativePosition) error {
return s.ids.Add(m, pos)
if s.head == nil {
s.head = &decoratedFinalizeHandler{nil, m}
s.tail = s.head
return nil
}
if pos == Before {
s.head = &decoratedFinalizeHandler{s.head, m}
} else {
tail := &decoratedFinalizeHandler{nil, m}
s.tail.Next = tail
s.tail = tail
}
return nil
}
// 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 (s *FinalizeStep) Insert(m FinalizeMiddleware, relativeTo string, pos RelativePosition) error {
return s.ids.Insert(m, relativeTo, pos)
found, prev := s.get(relativeTo)
if found == nil {
return fmt.Errorf("not found: %s", m.ID())
}
if pos == Before {
if prev == nil { // at the front
s.head = &decoratedFinalizeHandler{s.head, m}
} else { // somewhere in the middle
prev.Next = &decoratedFinalizeHandler{found, m}
}
} else {
if found.Next == nil { // at the end
tail := &decoratedFinalizeHandler{nil, m}
s.tail.Next = tail
s.tail = tail
} else { // somewhere in the middle
found.Next = &decoratedFinalizeHandler{found.Next, m}
}
}
return nil
}
// 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.
func (s *FinalizeStep) Swap(id string, m FinalizeMiddleware) (FinalizeMiddleware, error) {
removed, err := s.ids.Swap(id, m)
if err != nil {
return nil, err
found, _ := s.get(id)
if found == nil {
return nil, fmt.Errorf("not found: %s", m.ID())
}
return removed.(FinalizeMiddleware), nil
swapped := found.With
found.With = m
return swapped, nil
}
// Remove removes the middleware by id. Returns error if the middleware
// doesn't exist.
func (s *FinalizeStep) Remove(id string) (FinalizeMiddleware, error) {
removed, err := s.ids.Remove(id)
if err != nil {
return nil, err
found, prev := s.get(id)
if found == nil {
return nil, fmt.Errorf("not found: %s", id)
}
return removed.(FinalizeMiddleware), nil
if s.head == s.tail { // it's the only one
s.head = nil
s.tail = nil
} else if found == s.head { // at the front
s.head = s.head.Next.(*decoratedFinalizeHandler)
} else if found == s.tail { // at the end
prev.Next = nil
s.tail = prev
} else {
prev.Next = found.Next // somewhere in the middle
}
return found.With, nil
}
// List returns a list of the middleware in the step.
func (s *FinalizeStep) List() []string {
return s.ids.List()
var ids []string
for h := s.head; h != nil; {
ids = append(ids, h.With.ID())
if h.Next == nil {
break
}
// once executed, tail.Next of the list will be set to an
// *finalizeWrapHandler, make sure to check for that
if hnext, ok := h.Next.(*decoratedFinalizeHandler); ok {
h = hnext
} else {
break
}
}
return ids
}
// Clear removes all middleware in the step.
func (s *FinalizeStep) Clear() {
s.ids.Clear()
s.head = nil
s.tail = nil
}
func (s *FinalizeStep) get(id string) (found, prev *decoratedFinalizeHandler) {
for h := s.head; h != nil; {
if h.With.ID() == id {
found = h
return
}
prev = h
if h.Next == nil {
return
}
// once executed, tail.Next of the list will be set to an
// *finalizeWrapHandler
h, _ = h.Next.(*decoratedFinalizeHandler)
}
return
}
type finalizeWrapHandler struct {
@@ -200,10 +287,10 @@ func (h decoratedFinalizeHandler) HandleFinalize(ctx context.Context, in Finaliz
return h.With.HandleFinalize(ctx, in, h.Next)
}
// FinalizeHandlerFunc provides a wrapper around a function to be used as a finalize middleware handler.
// FinalizeHandlerFunc provides a wrapper around a function to be used as finalizeMiddleware.
type FinalizeHandlerFunc func(context.Context, FinalizeInput) (FinalizeOutput, Metadata, error)
// HandleFinalize invokes the wrapped function with the given arguments.
// HandleFinalize calls the wrapped function with the provided arguments.
func (f FinalizeHandlerFunc) HandleFinalize(ctx context.Context, in FinalizeInput) (FinalizeOutput, Metadata, error) {
return f(ctx, in)
}

View File

@@ -1,10 +1,15 @@
// Code generated by smithy-go/middleware/generate.go DO NOT EDIT.
package middleware
import "context"
import (
"context"
"fmt"
)
// 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{}
}
@@ -72,15 +77,14 @@ var _ InitializeMiddleware = (initializeMiddlewareFunc{})
// InitializeStep provides the ordered grouping of InitializeMiddleware to be
// invoked on a handler.
type InitializeStep struct {
ids *orderedIDs
head *decoratedInitializeHandler
tail *decoratedInitializeHandler
}
// NewInitializeStep returns an InitializeStep ready to have middleware for
// initialization added to it.
// initialize added to it.
func NewInitializeStep() *InitializeStep {
return &InitializeStep{
ids: newOrderedIDs(),
}
return &InitializeStep{}
}
var _ Middleware = (*InitializeStep)(nil)
@@ -97,77 +101,161 @@ func (s *InitializeStep) ID() string {
func (s *InitializeStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (
out interface{}, metadata Metadata, err error,
) {
order := s.ids.GetOrder()
var h InitializeHandler = initializeWrapHandler{Next: next}
for i := len(order) - 1; i >= 0; i-- {
h = decoratedInitializeHandler{
Next: h,
With: order[i].(InitializeMiddleware),
}
}
sIn := InitializeInput{
Parameters: in,
}
res, metadata, err := h.HandleInitialize(ctx, sIn)
wh := &initializeWrapHandler{next}
if s.head == nil {
res, metadata, err := wh.HandleInitialize(ctx, sIn)
return res.Result, metadata, err
}
s.tail.Next = wh
res, metadata, err := s.head.HandleInitialize(ctx, sIn)
return res.Result, metadata, err
}
// Get retrieves the middleware identified by id. If the middleware is not present, returns false.
func (s *InitializeStep) Get(id string) (InitializeMiddleware, bool) {
get, ok := s.ids.Get(id)
if !ok {
found, _ := s.get(id)
if found == nil {
return nil, false
}
return get.(InitializeMiddleware), ok
return found.With, true
}
// Add injects the middleware to the relative position of the middleware group.
// Returns an error if the middleware already exists.
//
// Add never returns an error. It used to for duplicate phases but this
// behavior has since been removed as part of a performance optimization. The
// return value from Add can be ignored.
func (s *InitializeStep) Add(m InitializeMiddleware, pos RelativePosition) error {
return s.ids.Add(m, pos)
if s.head == nil {
s.head = &decoratedInitializeHandler{nil, m}
s.tail = s.head
return nil
}
if pos == Before {
s.head = &decoratedInitializeHandler{s.head, m}
} else {
tail := &decoratedInitializeHandler{nil, m}
s.tail.Next = tail
s.tail = tail
}
return nil
}
// 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 (s *InitializeStep) Insert(m InitializeMiddleware, relativeTo string, pos RelativePosition) error {
return s.ids.Insert(m, relativeTo, pos)
found, prev := s.get(relativeTo)
if found == nil {
return fmt.Errorf("not found: %s", m.ID())
}
if pos == Before {
if prev == nil { // at the front
s.head = &decoratedInitializeHandler{s.head, m}
} else { // somewhere in the middle
prev.Next = &decoratedInitializeHandler{found, m}
}
} else {
if found.Next == nil { // at the end
tail := &decoratedInitializeHandler{nil, m}
s.tail.Next = tail
s.tail = tail
} else { // somewhere in the middle
found.Next = &decoratedInitializeHandler{found.Next, m}
}
}
return nil
}
// 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.
func (s *InitializeStep) Swap(id string, m InitializeMiddleware) (InitializeMiddleware, error) {
removed, err := s.ids.Swap(id, m)
if err != nil {
return nil, err
found, _ := s.get(id)
if found == nil {
return nil, fmt.Errorf("not found: %s", m.ID())
}
return removed.(InitializeMiddleware), nil
swapped := found.With
found.With = m
return swapped, nil
}
// Remove removes the middleware by id. Returns error if the middleware
// doesn't exist.
func (s *InitializeStep) Remove(id string) (InitializeMiddleware, error) {
removed, err := s.ids.Remove(id)
if err != nil {
return nil, err
found, prev := s.get(id)
if found == nil {
return nil, fmt.Errorf("not found: %s", id)
}
return removed.(InitializeMiddleware), nil
if s.head == s.tail { // it's the only one
s.head = nil
s.tail = nil
} else if found == s.head { // at the front
s.head = s.head.Next.(*decoratedInitializeHandler)
} else if found == s.tail { // at the end
prev.Next = nil
s.tail = prev
} else {
prev.Next = found.Next // somewhere in the middle
}
return found.With, nil
}
// List returns a list of the middleware in the step.
func (s *InitializeStep) List() []string {
return s.ids.List()
var ids []string
for h := s.head; h != nil; {
ids = append(ids, h.With.ID())
if h.Next == nil {
break
}
// once executed, tail.Next of the list will be set to an
// *initializeWrapHandler, make sure to check for that
if hnext, ok := h.Next.(*decoratedInitializeHandler); ok {
h = hnext
} else {
break
}
}
return ids
}
// Clear removes all middleware in the step.
func (s *InitializeStep) Clear() {
s.ids.Clear()
s.head = nil
s.tail = nil
}
func (s *InitializeStep) get(id string) (found, prev *decoratedInitializeHandler) {
for h := s.head; h != nil; {
if h.With.ID() == id {
found = h
return
}
prev = h
if h.Next == nil {
return
}
// once executed, tail.Next of the list will be set to an
// *initializeWrapHandler
h, _ = h.Next.(*decoratedInitializeHandler)
}
return
}
type initializeWrapHandler struct {
@@ -200,12 +288,12 @@ func (h decoratedInitializeHandler) HandleInitialize(ctx context.Context, in Ini
return h.With.HandleInitialize(ctx, in, h.Next)
}
// InitializeHandlerFunc provides a wrapper around a function to be used as an initialize middleware handler.
// InitializeHandlerFunc provides a wrapper around a function to be used as initializeMiddleware.
type InitializeHandlerFunc func(context.Context, InitializeInput) (InitializeOutput, Metadata, error)
// HandleInitialize calls the wrapped function with the provided arguments.
func (i InitializeHandlerFunc) HandleInitialize(ctx context.Context, in InitializeInput) (InitializeOutput, Metadata, error) {
return i(ctx, in)
func (f InitializeHandlerFunc) HandleInitialize(ctx context.Context, in InitializeInput) (InitializeOutput, Metadata, error) {
return f(ctx, in)
}
var _ InitializeHandler = InitializeHandlerFunc(nil)

View File

@@ -1,6 +1,10 @@
// Code generated by smithy-go/middleware/generate.go DO NOT EDIT.
package middleware
import "context"
import (
"context"
"fmt"
)
// SerializeInput provides the input parameters for the SerializeMiddleware to
// consume. SerializeMiddleware may modify the Request value before forwarding
@@ -41,8 +45,8 @@ type SerializeMiddleware interface {
)
}
// SerializeMiddlewareFunc returns a SerializeMiddleware with the unique ID
// provided, and the func to be invoked.
// SerializeMiddlewareFunc returns a SerializeMiddleware with the unique ID provided,
// and the func to be invoked.
func SerializeMiddlewareFunc(id string, fn func(context.Context, SerializeInput, SerializeHandler) (SerializeOutput, Metadata, error)) SerializeMiddleware {
return serializeMiddlewareFunc{
id: id,
@@ -75,17 +79,15 @@ var _ SerializeMiddleware = (serializeMiddlewareFunc{})
// SerializeStep provides the ordered grouping of SerializeMiddleware to be
// invoked on a handler.
type SerializeStep struct {
head *decoratedSerializeHandler
tail *decoratedSerializeHandler
newRequest func() interface{}
ids *orderedIDs
}
// 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.
// NewSerializeStep returns an SerializeStep ready to have middleware for
// serialize added to it.
func NewSerializeStep(newRequest func() interface{}) *SerializeStep {
return &SerializeStep{
ids: newOrderedIDs(),
newRequest: newRequest,
}
}
@@ -104,78 +106,162 @@ func (s *SerializeStep) ID() string {
func (s *SerializeStep) HandleMiddleware(ctx context.Context, in interface{}, next Handler) (
out interface{}, metadata Metadata, err error,
) {
order := s.ids.GetOrder()
var h SerializeHandler = serializeWrapHandler{Next: next}
for i := len(order) - 1; i >= 0; i-- {
h = decoratedSerializeHandler{
Next: h,
With: order[i].(SerializeMiddleware),
}
}
sIn := SerializeInput{
Parameters: in,
Request: s.newRequest(),
}
res, metadata, err := h.HandleSerialize(ctx, sIn)
wh := &serializeWrapHandler{next}
if s.head == nil {
res, metadata, err := wh.HandleSerialize(ctx, sIn)
return res.Result, metadata, err
}
s.tail.Next = wh
res, metadata, err := s.head.HandleSerialize(ctx, sIn)
return res.Result, metadata, err
}
// Get retrieves the middleware identified by id. If the middleware is not present, returns false.
func (s *SerializeStep) Get(id string) (SerializeMiddleware, bool) {
get, ok := s.ids.Get(id)
if !ok {
found, _ := s.get(id)
if found == nil {
return nil, false
}
return get.(SerializeMiddleware), ok
return found.With, true
}
// Add injects the middleware to the relative position of the middleware group.
// Returns an error if the middleware already exists.
//
// Add never returns an error. It used to for duplicate phases but this
// behavior has since been removed as part of a performance optimization. The
// return value from Add can be ignored.
func (s *SerializeStep) Add(m SerializeMiddleware, pos RelativePosition) error {
return s.ids.Add(m, pos)
if s.head == nil {
s.head = &decoratedSerializeHandler{nil, m}
s.tail = s.head
return nil
}
if pos == Before {
s.head = &decoratedSerializeHandler{s.head, m}
} else {
tail := &decoratedSerializeHandler{nil, m}
s.tail.Next = tail
s.tail = tail
}
return nil
}
// 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 (s *SerializeStep) Insert(m SerializeMiddleware, relativeTo string, pos RelativePosition) error {
return s.ids.Insert(m, relativeTo, pos)
found, prev := s.get(relativeTo)
if found == nil {
return fmt.Errorf("not found: %s", m.ID())
}
if pos == Before {
if prev == nil { // at the front
s.head = &decoratedSerializeHandler{s.head, m}
} else { // somewhere in the middle
prev.Next = &decoratedSerializeHandler{found, m}
}
} else {
if found.Next == nil { // at the end
tail := &decoratedSerializeHandler{nil, m}
s.tail.Next = tail
s.tail = tail
} else { // somewhere in the middle
found.Next = &decoratedSerializeHandler{found.Next, m}
}
}
return nil
}
// 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.
func (s *SerializeStep) Swap(id string, m SerializeMiddleware) (SerializeMiddleware, error) {
removed, err := s.ids.Swap(id, m)
if err != nil {
return nil, err
found, _ := s.get(id)
if found == nil {
return nil, fmt.Errorf("not found: %s", m.ID())
}
return removed.(SerializeMiddleware), nil
swapped := found.With
found.With = m
return swapped, nil
}
// Remove removes the middleware by id. Returns error if the middleware
// doesn't exist.
func (s *SerializeStep) Remove(id string) (SerializeMiddleware, error) {
removed, err := s.ids.Remove(id)
if err != nil {
return nil, err
found, prev := s.get(id)
if found == nil {
return nil, fmt.Errorf("not found: %s", id)
}
return removed.(SerializeMiddleware), nil
if s.head == s.tail { // it's the only one
s.head = nil
s.tail = nil
} else if found == s.head { // at the front
s.head = s.head.Next.(*decoratedSerializeHandler)
} else if found == s.tail { // at the end
prev.Next = nil
s.tail = prev
} else {
prev.Next = found.Next // somewhere in the middle
}
return found.With, nil
}
// List returns a list of the middleware in the step.
func (s *SerializeStep) List() []string {
return s.ids.List()
var ids []string
for h := s.head; h != nil; {
ids = append(ids, h.With.ID())
if h.Next == nil {
break
}
// once executed, tail.Next of the list will be set to an
// *serializeWrapHandler, make sure to check for that
if hnext, ok := h.Next.(*decoratedSerializeHandler); ok {
h = hnext
} else {
break
}
}
return ids
}
// Clear removes all middleware in the step.
func (s *SerializeStep) Clear() {
s.ids.Clear()
s.head = nil
s.tail = nil
}
func (s *SerializeStep) get(id string) (found, prev *decoratedSerializeHandler) {
for h := s.head; h != nil; {
if h.With.ID() == id {
found = h
return
}
prev = h
if h.Next == nil {
return
}
// once executed, tail.Next of the list will be set to an
// *serializeWrapHandler
h, _ = h.Next.(*decoratedSerializeHandler)
}
return
}
type serializeWrapHandler struct {
@@ -184,7 +270,7 @@ type serializeWrapHandler struct {
var _ SerializeHandler = (*serializeWrapHandler)(nil)
// Implements SerializeHandler, converts types and delegates to underlying
// HandleSerialize implements SerializeHandler, converts types and delegates to underlying
// generic handler.
func (w serializeWrapHandler) HandleSerialize(ctx context.Context, in SerializeInput) (
out SerializeOutput, metadata Metadata, err error,
@@ -208,12 +294,12 @@ func (h decoratedSerializeHandler) HandleSerialize(ctx context.Context, in Seria
return h.With.HandleSerialize(ctx, in, h.Next)
}
// SerializeHandlerFunc provides a wrapper around a function to be used as a serialize middleware handler.
// SerializeHandlerFunc provides a wrapper around a function to be used as serializeMiddleware.
type SerializeHandlerFunc func(context.Context, SerializeInput) (SerializeOutput, Metadata, error)
// HandleSerialize calls the wrapped function with the provided arguments.
func (s SerializeHandlerFunc) HandleSerialize(ctx context.Context, in SerializeInput) (SerializeOutput, Metadata, error) {
return s(ctx, in)
func (f SerializeHandlerFunc) HandleSerialize(ctx context.Context, in SerializeInput) (SerializeOutput, Metadata, error) {
return f(ctx, in)
}
var _ SerializeHandler = SerializeHandlerFunc(nil)