-
Notifications
You must be signed in to change notification settings - Fork 50
/
utils.go
50 lines (40 loc) · 1.06 KB
/
utils.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 ali_mns
import (
"net/http"
"time"
"github.com/gogap/errors"
)
func send(client MNSClient, decoder MNSDecoder, method Method, headers map[string]string, message interface{}, resource string, v interface{}) (statusCode int, err error) {
var resp *http.Response
if resp, err = client.Send(method, headers, message, resource); err != nil {
return
}
if resp != nil {
defer resp.Body.Close()
statusCode = resp.StatusCode
if resp.StatusCode != http.StatusCreated &&
resp.StatusCode != http.StatusOK &&
resp.StatusCode != http.StatusNoContent {
errResp := ErrorMessageResponse{}
if e := decoder.Decode(resp.Body, &errResp); e != nil {
err = ERR_UNMARSHAL_ERROR_RESPONSE_FAILED.New(errors.Params{"err": e})
return
}
err = ParseError(errResp, resource)
return
}
if v != nil {
if e := decoder.Decode(resp.Body, v); e != nil {
err = ERR_UNMARSHAL_RESPONSE_FAILED.New(errors.Params{"err": e})
return
}
}
}
return
}
func now() time.Time {
if TimeNowFunc == nil {
return time.Now()
}
return TimeNowFunc()
}