-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_queue.go
66 lines (55 loc) · 1.75 KB
/
create_queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2014, Truveris Inc. All Rights Reserved.
// Use of this source code is governed by the ISC license in the LICENSE file.
//
// See the API documentation for further information on CreateQueue and its
// attributes.
//
// http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_CreateQueue.html
//
package sqs
import (
"fmt"
"net/url"
)
type CreateQueueAttributes struct {
MaximumMessageSize int
ReceiveMessageWaitTimeSeconds int
VisibilityTimeout int
MessageRetentionPeriod int
Policy string
}
func (attrs CreateQueueAttributes) Map() map[string]string {
m := make(map[string]string)
if attrs.MaximumMessageSize > 0 {
m["MaximumMessageSize"] = fmt.Sprintf("%d", attrs.MaximumMessageSize)
}
if attrs.ReceiveMessageWaitTimeSeconds > 0 {
m["ReceiveMessageWaitTimeSeconds"] = fmt.Sprintf("%d",
attrs.ReceiveMessageWaitTimeSeconds)
}
if attrs.VisibilityTimeout > 0 {
m["VisibilityTimeout"] = fmt.Sprintf("%d", attrs.VisibilityTimeout)
}
if attrs.MessageRetentionPeriod > 0 {
m["MessageRetentionPeriod"] = fmt.Sprintf("%d", attrs.MessageRetentionPeriod)
}
return m
}
func (attrs CreateQueueAttributes) AddToQuery(query *url.Values) {
index := 1
for name, value := range attrs.Map() {
query.Set(fmt.Sprintf("Attribute.%d.Name", index), name)
query.Set(fmt.Sprintf("Attribute.%d.Value", index), value)
index++
}
}
func buildCreateQueueURL(endpointURL, name string, attributes CreateQueueAttributes) string {
query := url.Values{}
query.Set("Action", "CreateQueue")
query.Set("QueueName", name)
attributes.AddToQuery(&query)
query.Set("Version", SQSAPIVersion)
query.Set("SignatureVersion", SQSSignatureVersion)
url := endpointURL + "?" + query.Encode()
return url
}