Passed
Pull Request — master (#8)
by eval
01:37 queued 10s
created

dynamodb/client_op_item_get.go   A

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 51
dl 0
loc 88
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B dynamodb.GetItemRequest.ToInput 0 29 6
A dynamodb.*DynamoDB.GetItem 0 12 2
A dynamodb.NewGetItemResult 0 12 3
1
package dynamodb
2
3
import (
4
	"context"
5
6
	SDK "github.com/aws/aws-sdk-go-v2/service/dynamodb"
7
8
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/errors"
9
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers"
10
)
11
12
// GetItem executes `GetItem` operation.
13
func (svc *DynamoDB) GetItem(ctx context.Context, r GetItemRequest) (*GetItemResult, error) {
14
	out, err := svc.RawGetItem(ctx, r.ToInput())
15
	if err == nil {
16
		return NewGetItemResult(out), nil
17
	}
18
19
	err = svc.errWrap(errors.ErrorData{
20
		Err:          err,
21
		AWSOperation: "GetItem",
22
	})
23
	svc.Errorf(err.Error())
0 ignored issues
show
introduced by
can't check non-constant format in call to Errorf
Loading history...
24
	return nil, err
25
}
26
27
// GetItemRequest has parameters for `GetItem` operation.
28
type GetItemRequest struct {
29
	TableName string
30
	Key       map[string]AttributeValue
31
32
	// optional
33
	AttributesToGet          []string
34
	ConsistentRead           bool
35
	ExpressionAttributeNames map[string]string
36
	ProjectionExpression     string
37
	ReturnConsumedCapacity   ReturnConsumedCapacity
38
}
39
40
func (r GetItemRequest) ToInput() *SDK.GetItemInput {
0 ignored issues
show
introduced by
exported method GetItemRequest.ToInput should have comment or be unexported
Loading history...
41
	in := &SDK.GetItemInput{}
42
43
	if r.TableName != "" {
44
		in.TableName = pointers.String(r.TableName)
45
	}
46
47
	if len(r.Key) != 0 {
48
		m := make(map[string]SDK.AttributeValue, len(r.Key))
49
		for key, val := range r.Key {
50
			m[key] = val.ToSDK()
51
		}
52
		in.Key = m
53
	}
54
55
	in.AttributesToGet = r.AttributesToGet
56
57
	if r.ConsistentRead {
58
		in.ConsistentRead = pointers.Bool(r.ConsistentRead)
59
	}
60
61
	in.ExpressionAttributeNames = r.ExpressionAttributeNames
62
63
	if r.ProjectionExpression != "" {
64
		in.ProjectionExpression = pointers.String(r.ProjectionExpression)
65
	}
66
67
	in.ReturnConsumedCapacity = SDK.ReturnConsumedCapacity(r.ReturnConsumedCapacity)
68
	return in
69
}
70
71
// GetItemResult contains results from `GetItem` operation.
72
type GetItemResult struct {
73
	ConsumedCapacity ConsumedCapacity
74
	Item             map[string]AttributeValue
75
}
76
77
func NewGetItemResult(output *SDK.GetItemResponse) *GetItemResult {
0 ignored issues
show
introduced by
exported function NewGetItemResult should have comment or be unexported
Loading history...
78
	r := &GetItemResult{}
79
	if output == nil {
80
		return r
81
	}
82
83
	if output.ConsumedCapacity != nil {
84
		r.ConsumedCapacity = newConsumedCapacity(*output.ConsumedCapacity)
85
	}
86
87
	r.Item = newAttributeValueMap(output.Item)
88
	return r
89
}
90