Passed
Push — master ( 00fce0...e4f177 )
by eval
02:21 queued 32s
created

sqs.*SQS.XIsEmptyQueue   B

Complexity

Conditions 6

Size

Total Lines 29
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 21
nop 2
dl 0
loc 29
rs 8.4426
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
	attrList := []QueueAttributeName{
11
		QueueAttributeNameApproximateNumberOfMessages,
12
		QueueAttributeNameApproximateNumberOfMessagesDelayed,
13
		QueueAttributeNameApproximateNumberOfMessagesNotVisible,
14
	}
15
	resp, err := svc.GetQueueAttributes(ctx, GetQueueAttributesRequest{
16
		QueueURL:       queueURL,
17
		AttributeNames: attrList,
18
	})
19
	if err != nil {
20
		return false, err
21
	}
22
23
	result := resp.Attributes
24
	for _, v := range attrList {
25
		attr, ok := result[string(v)]
26
		if !ok {
27
			return false, nil
28
		}
29
		num, err := strconv.Atoi(attr)
30
		if err != nil {
31
			return false, err
32
		}
33
		if num > 0 {
34
			return false, nil
35
		}
36
	}
37
	return true, nil
38
}
39