zhangzengfei
2024-05-17 9ee887fce2f87f7a79d0b94640cf1d341a254319
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
package client
 
import (
    "encoding/json"
    "gat1400Exchange/pkg/logger"
    "gat1400Exchange/util"
    "gat1400Exchange/vo"
)
 
func Notify(url string, msg []byte) int {
    if clientStatus != vo.StatusSuccess {
        return clientStatus
    }
 
    rsp, err := util.HttpPost(url, headers, msg)
    if err != nil {
        logger.Warn("Post notification failed, %s", err.Error())
        return vo.StatusOtherError
    }
 
    var stat vo.ResponseStatusList
    err = json.Unmarshal(rsp, &stat)
    if err != nil {
        logger.Warn("Post notification response unmarshal failed, %s", err.Error())
        return vo.StatusOtherError
    }
 
    logger.Debug("Post notification success.")
 
    return vo.StatusSuccess
}
 
func Subscribe(url string, msg []byte) int {
    //if clientStatus != vo.StatusSuccess {
    //    return clientStatus
    //}
 
    rsp, err := util.HttpPost(url, headers, msg)
    if err != nil {
        logger.Warn("Post subscribe failed, %s", err.Error())
        return vo.StatusOtherError
    }
 
    var stat vo.ResponseStatusList
    err = json.Unmarshal(rsp, &stat)
    if err != nil {
        logger.Warn("Post subscribe response unmarshal failed, %s", err.Error())
        logger.Warn("response, %s", string(rsp))
        return vo.StatusOtherError
    }
 
    logger.Debug("Post notification success.")
 
    return vo.StatusSuccess
}