forked from xiaojiaoyu100/aliyun-mns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_topic_attributes.go
50 lines (41 loc) · 950 Bytes
/
set_topic_attributes.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
package alimns
import (
"errors"
"fmt"
"net/http"
)
// SetTopicAttributes 修改主题的属性
func (c *Client) SetTopicAttributes(topic string, setters ...TopicAttributeSetter) error {
var err error
if !checkTopicName(topic) {
return errors.New("unqualified topic name")
}
attri := DefaultTopicAttr()
for _, setter := range setters {
err = setter(&attri)
if err != nil {
return err
}
}
requestLine := fmt.Sprintf(mnsSetTopicAttributes, topic)
req := c.ca.NewRequest().Put().WithPath(requestLine).WithXMLBody(&attri).WithTimeout(apiTimeout)
resp, err := c.ca.Do(req)
if err != nil {
return err
}
switch resp.StatusCode() {
case http.StatusNoContent:
return nil
default:
var respErr RespErr
if err := resp.DecodeFromXML(&respErr); err != nil {
return nil
}
switch respErr.Code {
case topicNotExistError.Error():
return topicNotExistError
default:
return errors.New(respErr.Code)
}
}
}