api_op_GetUserData.go (1535B)
1 package imds 2 3 import ( 4 "context" 5 "io" 6 7 "github.com/aws/smithy-go/middleware" 8 smithyhttp "github.com/aws/smithy-go/transport/http" 9 ) 10 11 const getUserDataPath = "/latest/user-data" 12 13 // GetUserData uses the path provided to request information from the EC2 14 // instance metadata service for dynamic data. The content will be returned 15 // as a string, or error if the request failed. 16 func (c *Client) GetUserData(ctx context.Context, params *GetUserDataInput, optFns ...func(*Options)) (*GetUserDataOutput, error) { 17 if params == nil { 18 params = &GetUserDataInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "GetUserData", params, optFns, 22 addGetUserDataMiddleware, 23 ) 24 if err != nil { 25 return nil, err 26 } 27 28 out := result.(*GetUserDataOutput) 29 out.ResultMetadata = metadata 30 return out, nil 31 } 32 33 // GetUserDataInput provides the input parameters for the GetUserData 34 // operation. 35 type GetUserDataInput struct{} 36 37 // GetUserDataOutput provides the output parameters for the GetUserData 38 // operation. 39 type GetUserDataOutput struct { 40 Content io.ReadCloser 41 42 ResultMetadata middleware.Metadata 43 } 44 45 func addGetUserDataMiddleware(stack *middleware.Stack, options Options) error { 46 return addAPIRequestMiddleware(stack, 47 options, 48 "GetUserData", 49 buildGetUserDataPath, 50 buildGetUserDataOutput) 51 } 52 53 func buildGetUserDataPath(params interface{}) (string, error) { 54 return getUserDataPath, nil 55 } 56 57 func buildGetUserDataOutput(resp *smithyhttp.Response) (interface{}, error) { 58 return &GetUserDataOutput{ 59 Content: resp.Body, 60 }, nil 61 }