-
Notifications
You must be signed in to change notification settings - Fork 7
/
batch_peek_message.go
47 lines (41 loc) · 1.13 KB
/
batch_peek_message.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
package alimns
import (
"context"
"encoding/xml"
"errors"
"fmt"
"net/http"
)
// BatchPeekMessageResponse 批量查看消息
type BatchPeekMessageResponse struct {
XMLName xml.Name `xml:"Messages"`
XMLNs string `xml:"xmlns,attr"`
PeekMessages []*PeekMessage `xml:"Message"`
}
// BatchPeekMessage 批量查看消息
func (c *Client) BatchPeekMessage(name string) (*BatchPeekMessageResponse, error) {
var err error
requestLine := fmt.Sprintf(mnsBatchPeekMessage, name, "16")
req := c.ca.NewRequest().Get().WithPath(requestLine).WithTimeout(apiTimeout)
resp, err := c.ca.Do(context.TODO(), req)
if err != nil {
return nil, err
}
switch resp.StatusCode() {
case http.StatusOK:
var batchPeekMessageResponse BatchPeekMessageResponse
if err := resp.DecodeFromXML(&batchPeekMessageResponse); err != nil {
return nil, err
}
return &batchPeekMessageResponse, nil
default:
var respErr RespErr
if err := resp.DecodeFromXML(&respErr); err != nil {
return nil, err
}
if respErr.Code == queueNotExistError.Error() {
return nil, queueNotExistError
}
return nil, errors.New(respErr.Code)
}
}