forked from xiaojiaoyu100/aliyun-mns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_visibility_timeout.go
58 lines (51 loc) · 1.55 KB
/
change_visibility_timeout.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
package alimns
import (
"encoding/xml"
"errors"
"fmt"
"net/http"
"strconv"
)
// ChangeVisibilityTimeoutResponse 修改消息可见时长回复
type ChangeVisibilityTimeoutResponse struct {
XMLName xml.Name `xml:"ChangeVisibility"`
XMLNs string `xml:"xmlns,attr"`
ReceiptHandle string `xml:"ReceiptHandle"`
NextVisibleTime int64 `xml:"NextVisibleTime"`
}
// ChangeVisibilityTimeout 修改消息可见时长
func (c *Client) ChangeVisibilityTimeout(
name,
receiptHandle string,
visibilityTimeout int) (*ChangeVisibilityTimeoutResponse, error) {
var err error
if visibilityTimeout < minVisibilityTimeout || visibilityTimeout > maxVisibilityTimeout {
return nil, visibilityTimeoutError
}
requestLine := fmt.Sprintf(mnsChangeMessageVisibility, name, receiptHandle, strconv.Itoa(visibilityTimeout))
req := c.ca.NewRequest().Put().WithPath(requestLine).WithTimeout(apiTimeout)
resp, err := c.ca.Do(req)
if err != nil {
return nil, err
}
switch resp.StatusCode() {
case http.StatusOK:
var changeVisibilityTimeoutResponse ChangeVisibilityTimeoutResponse
if err := resp.DecodeFromXML(&changeVisibilityTimeoutResponse); err != nil {
return nil, err
}
return &changeVisibilityTimeoutResponse, nil
default:
var respErr RespErr
if err := resp.DecodeFromXML(&respErr); err != nil {
return nil, err
}
switch respErr.Code {
case messageNotExistError.Error():
return nil, messageNotExistError
case queueNotExistError.Error():
return nil, queueNotExistError
}
return nil, errors.New(respErr.Message)
}
}