File: api_op_GetDynamicData.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.17.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 384,244 kB
  • sloc: java: 13,538; makefile: 400; sh: 137
file content (76 lines) | stat: -rw-r--r-- 2,108 bytes parent folder | download
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package imds

import (
	"context"
	"fmt"
	"io"

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

const getDynamicDataPath = "/latest/dynamic"

// GetDynamicData uses the path provided to request information from the EC2
// instance metadata service for dynamic data. The content will be returned
// as a string, or error if the request failed.
func (c *Client) GetDynamicData(ctx context.Context, params *GetDynamicDataInput, optFns ...func(*Options)) (*GetDynamicDataOutput, error) {
	if params == nil {
		params = &GetDynamicDataInput{}
	}

	result, metadata, err := c.invokeOperation(ctx, "GetDynamicData", params, optFns,
		addGetDynamicDataMiddleware,
	)
	if err != nil {
		return nil, err
	}

	out := result.(*GetDynamicDataOutput)
	out.ResultMetadata = metadata
	return out, nil
}

// GetDynamicDataInput provides the input parameters for the GetDynamicData
// operation.
type GetDynamicDataInput struct {
	// The relative dynamic data path to retrieve. Can be empty string to
	// retrieve a response containing a new line separated list of dynamic data
	// resources available.
	//
	// Must not include the dynamic data base path.
	//
	// May include leading slash. If Path includes trailing slash the trailing
	// slash will be included in the request for the resource.
	Path string
}

// GetDynamicDataOutput provides the output parameters for the GetDynamicData
// operation.
type GetDynamicDataOutput struct {
	Content io.ReadCloser

	ResultMetadata middleware.Metadata
}

func addGetDynamicDataMiddleware(stack *middleware.Stack, options Options) error {
	return addAPIRequestMiddleware(stack,
		options,
		buildGetDynamicDataPath,
		buildGetDynamicDataOutput)
}

func buildGetDynamicDataPath(params interface{}) (string, error) {
	p, ok := params.(*GetDynamicDataInput)
	if !ok {
		return "", fmt.Errorf("unknown parameter type %T", params)
	}

	return appendURIPath(getDynamicDataPath, p.Path), nil
}

func buildGetDynamicDataOutput(resp *smithyhttp.Response) (interface{}, error) {
	return &GetDynamicDataOutput{
		Content: resp.Body,
	}, nil
}