1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package dynamodb
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// The GetItem operation returns a set of attributes for the item with the given
15// primary key. If there is no matching item, GetItem does not return any data and
16// there will be no Item element in the response. GetItem provides an eventually
17// consistent read by default. If your application requires a strongly consistent
18// read, set ConsistentRead to true. Although a strongly consistent read might take
19// more time than an eventually consistent read, it always returns the last updated
20// value.
21func (c *Client) GetItem(ctx context.Context, params *GetItemInput, optFns ...func(*Options)) (*GetItemOutput, error) {
22	if params == nil {
23		params = &GetItemInput{}
24	}
25
26	result, metadata, err := c.invokeOperation(ctx, "GetItem", params, optFns, addOperationGetItemMiddlewares)
27	if err != nil {
28		return nil, err
29	}
30
31	out := result.(*GetItemOutput)
32	out.ResultMetadata = metadata
33	return out, nil
34}
35
36// Represents the input of a GetItem operation.
37type GetItemInput struct {
38
39	// A map of attribute names to AttributeValue objects, representing the primary key
40	// of the item to retrieve. For the primary key, you must provide all of the
41	// attributes. For example, with a simple primary key, you only need to provide a
42	// value for the partition key. For a composite primary key, you must provide
43	// values for both the partition key and the sort key.
44	//
45	// This member is required.
46	Key map[string]types.AttributeValue
47
48	// The name of the table containing the requested item.
49	//
50	// This member is required.
51	TableName *string
52
53	// This is a legacy parameter. Use ProjectionExpression instead. For more
54	// information, see AttributesToGet
55	// (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.AttributesToGet.html)
56	// in the Amazon DynamoDB Developer Guide.
57	AttributesToGet []string
58
59	// Determines the read consistency model: If set to true, then the operation uses
60	// strongly consistent reads; otherwise, the operation uses eventually consistent
61	// reads.
62	ConsistentRead *bool
63
64	// One or more substitution tokens for attribute names in an expression. The
65	// following are some use cases for using ExpressionAttributeNames:
66	//
67	// * To access an
68	// attribute whose name conflicts with a DynamoDB reserved word.
69	//
70	// * To create a
71	// placeholder for repeating occurrences of an attribute name in an expression.
72	//
73	// *
74	// To prevent special characters in an attribute name from being misinterpreted in
75	// an expression.
76	//
77	// Use the # character in an expression to dereference an attribute
78	// name. For example, consider the following attribute name:
79	//
80	// * Percentile
81	//
82	// The
83	// name of this attribute conflicts with a reserved word, so it cannot be used
84	// directly in an expression. (For the complete list of reserved words, see
85	// Reserved Words
86	// (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html)
87	// in the Amazon DynamoDB Developer Guide). To work around this, you could specify
88	// the following for ExpressionAttributeNames:
89	//
90	// * {"#P":"Percentile"}
91	//
92	// You could
93	// then use this substitution in an expression, as in this example:
94	//
95	// * #P =
96	// :val
97	//
98	// Tokens that begin with the : character are expression attribute values,
99	// which are placeholders for the actual value at runtime. For more information on
100	// expression attribute names, see Specifying Item Attributes
101	// (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.AccessingItemAttributes.html)
102	// in the Amazon DynamoDB Developer Guide.
103	ExpressionAttributeNames map[string]string
104
105	// A string that identifies one or more attributes to retrieve from the table.
106	// These attributes can include scalars, sets, or elements of a JSON document. The
107	// attributes in the expression must be separated by commas. If no attribute names
108	// are specified, then all attributes are returned. If any of the requested
109	// attributes are not found, they do not appear in the result. For more
110	// information, see Specifying Item Attributes
111	// (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.AccessingItemAttributes.html)
112	// in the Amazon DynamoDB Developer Guide.
113	ProjectionExpression *string
114
115	// Determines the level of detail about provisioned throughput consumption that is
116	// returned in the response:
117	//
118	// * INDEXES - The response includes the aggregate
119	// ConsumedCapacity for the operation, together with ConsumedCapacity for each
120	// table and secondary index that was accessed. Note that some operations, such as
121	// GetItem and BatchGetItem, do not access any indexes at all. In these cases,
122	// specifying INDEXES will only return ConsumedCapacity information for
123	// table(s).
124	//
125	// * TOTAL - The response includes only the aggregate ConsumedCapacity
126	// for the operation.
127	//
128	// * NONE - No ConsumedCapacity details are included in the
129	// response.
130	ReturnConsumedCapacity types.ReturnConsumedCapacity
131}
132
133// Represents the output of a GetItem operation.
134type GetItemOutput struct {
135
136	// The capacity units consumed by the GetItem operation. The data returned includes
137	// the total provisioned throughput consumed, along with statistics for the table
138	// and any indexes involved in the operation. ConsumedCapacity is only returned if
139	// the ReturnConsumedCapacity parameter was specified. For more information, see
140	// Read/Write Capacity Mode
141	// (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ProvisionedThroughputIntro.html)
142	// in the Amazon DynamoDB Developer Guide.
143	ConsumedCapacity *types.ConsumedCapacity
144
145	// A map of attribute names to AttributeValue objects, as specified by
146	// ProjectionExpression.
147	Item map[string]types.AttributeValue
148
149	// Metadata pertaining to the operation's result.
150	ResultMetadata middleware.Metadata
151}
152
153func addOperationGetItemMiddlewares(stack *middleware.Stack, options Options) (err error) {
154	err = stack.Serialize.Add(&awsAwsjson10_serializeOpGetItem{}, middleware.After)
155	if err != nil {
156		return err
157	}
158	err = stack.Deserialize.Add(&awsAwsjson10_deserializeOpGetItem{}, middleware.After)
159	if err != nil {
160		return err
161	}
162	if err = addSetLoggerMiddleware(stack, options); err != nil {
163		return err
164	}
165	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
166		return err
167	}
168	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
169		return err
170	}
171	if err = addResolveEndpointMiddleware(stack, options); err != nil {
172		return err
173	}
174	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
175		return err
176	}
177	if err = addRetryMiddlewares(stack, options); err != nil {
178		return err
179	}
180	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
181		return err
182	}
183	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
184		return err
185	}
186	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
187		return err
188	}
189	if err = addClientUserAgent(stack); err != nil {
190		return err
191	}
192	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
193		return err
194	}
195	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
196		return err
197	}
198	if err = addOpGetItemValidationMiddleware(stack); err != nil {
199		return err
200	}
201	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetItem(options.Region), middleware.Before); err != nil {
202		return err
203	}
204	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
205		return err
206	}
207	if err = addResponseErrorMiddleware(stack); err != nil {
208		return err
209	}
210	if err = addValidateResponseChecksum(stack, options); err != nil {
211		return err
212	}
213	if err = addAcceptEncodingGzip(stack, options); err != nil {
214		return err
215	}
216	if err = addRequestResponseLogging(stack, options); err != nil {
217		return err
218	}
219	return nil
220}
221
222func newServiceMetadataMiddleware_opGetItem(region string) *awsmiddleware.RegisterServiceMetadata {
223	return &awsmiddleware.RegisterServiceMetadata{
224		Region:        region,
225		ServiceID:     ServiceID,
226		SigningName:   "dynamodb",
227		OperationName: "GetItem",
228	}
229}
230