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

sqs/client_xapi_attributes.go   A

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 20
dl 0
loc 34
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A sqs.*SQS.XIsEmptyQueue 0 26 5
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