File: apiversion.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.30.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 662,428 kB
  • sloc: java: 16,875; makefile: 432; sh: 175
file content (46 lines) | stat: -rw-r--r-- 1,358 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package customizations

import (
	"context"
	"fmt"

	"github.com/aws/smithy-go"
	"github.com/aws/smithy-go/middleware"
	smithyhttp "github.com/aws/smithy-go/transport/http"
)

const glacierAPIVersionHeaderKey = "X-Amz-Glacier-Version"

// AddGlacierAPIVersionMiddleware explicitly add handling for the Glacier api version
// middleware to the operation stack.
func AddGlacierAPIVersionMiddleware(stack *middleware.Stack, apiVersion string) error {
	return stack.Serialize.Add(&GlacierAPIVersion{apiVersion: apiVersion}, middleware.Before)
}

// GlacierAPIVersion handles automatically setting Glacier's API version header.
type GlacierAPIVersion struct {
	apiVersion string
}

// ID returns the id for the middleware.
func (*GlacierAPIVersion) ID() string {
	return "Glacier:APIVersion"
}

// HandleSerialize implements the SerializeMiddleware interface
func (m *GlacierAPIVersion) HandleSerialize(
	ctx context.Context, input middleware.SerializeInput, next middleware.SerializeHandler,
) (
	output middleware.SerializeOutput, metadata middleware.Metadata, err error,
) {
	req, ok := input.Request.(*smithyhttp.Request)
	if !ok {
		return output, metadata, &smithy.SerializationError{
			Err: fmt.Errorf("unknown request type %T", input.Request),
		}
	}

	req.Header.Set(glacierAPIVersionHeaderKey, m.apiVersion)

	return next.HandleSerialize(ctx, input)
}