Passed
Push — master ( 9acbae...8ba3ae )
by eval
03:10 queued 01:28
created

sqs.ReceiveMessageRequest.ToInput   C

Complexity

Conditions 9

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 21
nop 0
dl 0
loc 31
rs 6.6666
c 0
b 0
f 0
1
package sqs
2
3
import (
4
	"context"
5
6
	SDK "github.com/aws/aws-sdk-go-v2/service/sqs"
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
// ReceiveMessage executes `ReceiveMessage` operation.
13
func (svc *SQS) ReceiveMessage(ctx context.Context, r ReceiveMessageRequest) (*ReceiveMessageResult, error) {
14
	out, err := svc.RawReceiveMessage(ctx, r.ToInput())
15
	if err != nil {
16
		err = svc.errWrap(errors.ErrorData{
17
			Err:          err,
18
			AWSOperation: "ReceiveMessage",
19
		})
20
		svc.Errorf(err.Error())
0 ignored issues
show
introduced by
can't check non-constant format in call to Errorf
Loading history...
21
		return nil, err
22
	}
23
	return NewReceiveMessageResult(out), nil
24
}
25
26
// ReceiveMessageRequest has parameters for `ReceiveMessage` operation.
27
type ReceiveMessageRequest struct {
28
	QueueURL string
29
30
	AttributeNames          []QueueAttributeName
31
	MaxNumberOfMessages     int64
32
	MessageAttributeNames   []string
33
	ReceiveRequestAttemptID string
34
	VisibilityTimeout       int64
35
	WaitTimeSeconds         int64
36
37
	// set if you want to force to use short polling
38
	UseShortPolling bool
39
}
40
41
func (r ReceiveMessageRequest) ToInput() *SDK.ReceiveMessageInput {
0 ignored issues
show
introduced by
exported method ReceiveMessageRequest.ToInput should have comment or be unexported
Loading history...
42
	in := &SDK.ReceiveMessageInput{}
43
44
	if r.QueueURL != "" {
45
		in.QueueUrl = pointers.String(r.QueueURL)
46
	}
47
48
	if len(r.AttributeNames) != 0 {
49
		list := make([]SDK.QueueAttributeName, len(r.AttributeNames))
50
		for i, v := range r.AttributeNames {
51
			list[i] = SDK.QueueAttributeName(v)
52
		}
53
		in.AttributeNames = list
54
	}
55
	if r.MaxNumberOfMessages != 0 {
56
		in.MaxNumberOfMessages = pointers.Long64(r.MaxNumberOfMessages)
57
	}
58
	r.MessageAttributeNames = in.MessageAttributeNames
59
	if r.ReceiveRequestAttemptID != "" {
60
		in.ReceiveRequestAttemptId = pointers.String(r.ReceiveRequestAttemptID)
61
	}
62
	if r.VisibilityTimeout != 0 {
63
		in.VisibilityTimeout = pointers.Long64(r.VisibilityTimeout)
64
	}
65
	if r.WaitTimeSeconds != 0 {
66
		in.WaitTimeSeconds = pointers.Long64(r.WaitTimeSeconds)
67
	}
68
	if r.UseShortPolling {
69
		in.WaitTimeSeconds = pointers.Long64(0)
70
	}
71
	return in
72
}
73
74
type ReceiveMessageResult struct {
0 ignored issues
show
introduced by
exported type ReceiveMessageResult should have comment or be unexported
Loading history...
75
	Messages []Message
76
}
77
78
func NewReceiveMessageResult(o *SDK.ReceiveMessageResponse) *ReceiveMessageResult {
0 ignored issues
show
introduced by
exported function NewReceiveMessageResult should have comment or be unexported
Loading history...
79
	result := &ReceiveMessageResult{}
80
	if o == nil {
81
		return result
82
	}
83
84
	if len(o.Messages) != 0 {
85
		list := make([]Message, len(o.Messages))
86
		for i, v := range o.Messages {
87
			list[i] = newMessage(v)
88
		}
89
		result.Messages = list
90
	}
91
	return result
92
}
93