add management interface and callback args optimization

This commit is contained in:
Gordon
2021-11-16 16:04:34 +08:00
parent 3329068bcc
commit 09fd45346e
6 changed files with 84 additions and 43 deletions
+3 -2
View File
@@ -155,8 +155,9 @@ type config struct {
AccessExpire int64 `yaml:"accessExpire"`
}
MessageCallBack struct {
CallbackSwitch bool `yaml:"callbackSwitch"`
CallbackUrl string `yaml:"callbackUrl"`
CallbackSwitch bool `yaml:"callbackSwitch"`
CallbackUrl string `yaml:"callbackUrl"`
CallBackTimeOut int `yaml:"callbackTimeOut"`
}
}
+4
View File
@@ -32,9 +32,13 @@ const (
Video = 104
File = 105
AtText = 106
Merger = 107
Card = 108
Location = 109
Custom = 110
HasReadReceipt = 112
Typing = 113
Quote = 114
Common = 200
GroupMsg = 201
+8 -6
View File
@@ -29,22 +29,24 @@ func Get(url string) (response []byte, err error) {
}
//application/json; charset=utf-8
func Post(url string, data interface{}, contentType string) (content []byte, err error) {
jsonStr, _ := json.Marshal(data)
func Post(url string, data interface{}, timeOutSecond int) (content []byte, err error) {
jsonStr, err := json.Marshal(data)
if err != nil {
return nil, err
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
if err != nil {
return nil, err
}
req.Header.Add("content-type", contentType)
defer req.Body.Close()
req.Close = true
req.Header.Add("content-type", "application/json; charset=utf-8")
client := &http.Client{Timeout: 5 * time.Second}
client := &http.Client{Timeout: time.Duration(timeOutSecond) * time.Second}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
result, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err