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

sqs.NewSendMessageResult   B

Complexity

Conditions 7

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 15
nop 1
dl 0
loc 22
rs 8
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
// SendMessage executes `SendMessage` operation.
13
func (svc *SQS) SendMessage(ctx context.Context, r SendMessageRequest) (*SendMessageResult, error) {
14
	out, err := svc.RawSendMessage(ctx, r.ToInput())
15
	if err != nil {
16
		err = svc.errWrap(errors.ErrorData{
17
			Err:          err,
18
			AWSOperation: "SendMessage",
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 NewSendMessageResult(out), nil
24
}
25
26
// SendMessageRequest has parameters for `SendMessage` operation.
27
type SendMessageRequest struct {
28
	MessageBody string
29
	QueueURL    string
30
31
	// for FIFO
32
	MessageDeduplicationID string
33
	MessageGroupID         string
34
35
	DelaySeconds            int64
36
	MessageAttributes       map[string]MessageAttributeValue
37
	MessageSystemAttributes map[string]MessageSystemAttributeValue
38
}
39
40
func (r SendMessageRequest) ToInput() *SDK.SendMessageInput {
0 ignored issues
show
introduced by
exported method SendMessageRequest.ToInput should have comment or be unexported
Loading history...
41
	in := &SDK.SendMessageInput{}
42
43
	if r.MessageBody != "" {
44
		in.MessageBody = pointers.String(r.MessageBody)
45
	}
46
	if r.QueueURL != "" {
47
		in.QueueUrl = pointers.String(r.QueueURL)
48
	}
49
50
	if r.MessageDeduplicationID != "" {
51
		in.MessageDeduplicationId = pointers.String(r.MessageDeduplicationID)
52
	}
53
	if r.MessageGroupID != "" {
54
		in.MessageGroupId = pointers.String(r.MessageGroupID)
55
	}
56
57
	if r.DelaySeconds != 0 {
58
		in.DelaySeconds = pointers.Long64(r.DelaySeconds)
59
	}
60
	if len(r.MessageAttributes) != 0 {
61
		m := make(map[string]SDK.MessageAttributeValue)
62
		for k, v := range r.MessageAttributes {
63
			m[k] = v.ToSDK()
64
		}
65
		in.MessageAttributes = m
66
	}
67
	if len(r.MessageSystemAttributes) != 0 {
68
		m := make(map[string]SDK.MessageSystemAttributeValue)
69
		for k, v := range r.MessageSystemAttributes {
70
			m[k] = v.ToSDK()
71
		}
72
		in.MessageSystemAttributes = m
73
	}
74
	return in
75
}
76
77
type SendMessageResult struct {
0 ignored issues
show
introduced by
exported type SendMessageResult should have comment or be unexported
Loading history...
78
	MD5OfMessageAttributes       string
79
	MD5OfMessageBody             string
80
	MD5OfMessageSystemAttributes string
81
	MessageID                    string
82
83
	// for FIFO
84
	SequenceNumber string
85
}
86
87
func NewSendMessageResult(o *SDK.SendMessageResponse) *SendMessageResult {
0 ignored issues
show
introduced by
exported function NewSendMessageResult should have comment or be unexported
Loading history...
88
	result := &SendMessageResult{}
89
	if o == nil {
90
		return result
91
	}
92
93
	if o.MD5OfMessageAttributes != nil {
94
		result.MD5OfMessageAttributes = *o.MD5OfMessageAttributes
95
	}
96
	if o.MD5OfMessageBody != nil {
97
		result.MD5OfMessageBody = *o.MD5OfMessageBody
98
	}
99
	if o.MD5OfMessageSystemAttributes != nil {
100
		result.MD5OfMessageSystemAttributes = *o.MD5OfMessageSystemAttributes
101
	}
102
	if o.MessageId != nil {
103
		result.MessageID = *o.MessageId
104
	}
105
	if o.SequenceNumber != nil {
106
		result.SequenceNumber = *o.SequenceNumber
107
	}
108
	return result
109
}
110