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

sqs.*SQS.XIsEmptyQueue   A

Complexity

Conditions 5

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 16
nop 2
dl 0
loc 26
rs 9.1333
c 0
b 0
f 0
1
package sqs
2
3
import (
4
	"context"
5
	"strconv"
6
)
7
8
// XIsEmptyQueue checks if the queue does not have any message.
9
func (svc *SQS) XIsEmptyQueue(ctx context.Context, queueURL string) (bool, error) {
10
	resp, err := svc.GetQueueAttributes(ctx, GetQueueAttributesRequest{
11
		QueueURL: queueURL,
12
		AttributeNames: []QueueAttributeName{
13
			QueueAttributeNameApproximateNumberOfMessages,
14
			QueueAttributeNameApproximateNumberOfMessagesDelayed,
15
			QueueAttributeNameApproximateNumberOfMessagesNotVisible,
16
		},
17
	})
18
	if err != nil {
19
		return false, err
20
	}
21
22
	// if v, ok := resp.Attributes[QueueAttributeNameApproximateNumberOfMessages]; ok {
23
24
	// }
25
	for _, v := range resp.Attributes {
26
		num, err := strconv.Atoi(v)
27
		if err != nil {
28
			return false, err
29
		}
30
		if num > 0 {
31
			return false, nil
32
		}
33
	}
34
	return true, nil
35
}
36