-
Notifications
You must be signed in to change notification settings - Fork 7
/
list_queue.go
65 lines (56 loc) · 1.38 KB
/
list_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
package alimns
import (
"context"
"encoding/xml"
"errors"
"net/http"
)
// ListQueueRequest 获取队列列表参数
type ListQueueRequest struct {
Marker string
RetNumber string
Prefix string
}
// QueueData 队列的属性
type QueueData struct {
QueueURL string `xml:"QueueURL"`
}
// ListQueueResponse 获取队列的回复
type ListQueueResponse struct {
XMLName xml.Name `xml:"Queues"`
XMLNs string `xml:"xmlns,attr"`
Queues []*QueueData `xml:"Queue"`
NextMarker string `xml:"NextMarker"`
}
// ListQueue 请求队列列表
func (c *Client) ListQueue(request *ListQueueRequest) (*ListQueueResponse, error) {
var err error
req := c.ca.NewRequest().Get().WithPath(mnsListQueue).WithTimeout(apiTimeout)
if request.Marker != "" {
req.SetHeader(xMnsMarker, request.Marker)
}
if request.RetNumber != "" {
req.SetHeader(xMnsRetNumber, request.RetNumber)
}
if request.Prefix != "" {
req.SetHeader(xMnxPrefix, request.Prefix)
}
resp, err := c.ca.Do(context.TODO(), req)
if err != nil {
return nil, err
}
switch resp.StatusCode() {
case http.StatusOK:
var response ListQueueResponse
if err := resp.DecodeFromXML(&response); err != nil {
return nil, err
}
return &response, nil
default:
var respErr RespErr
if err := resp.DecodeFromXML(&respErr); err != nil {
return nil, err
}
return nil, errors.New(respErr.Code)
}
}