You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
815 B
36 lines
815 B
package base |
|
|
|
import ( |
|
"encoding/json" |
|
"io/ioutil" |
|
"net/http" |
|
"time" |
|
|
|
"github.com/liangdas/mqant/log" |
|
) |
|
|
|
// status=1时,属于不知道第三方是什么情况的报错,不能当成业务中断 |
|
// status=0时,可以根据返回判断是否是业务错误 |
|
func Request(req *http.Request, ret interface{}) int { |
|
client := &http.Client{ |
|
Timeout: 30 * time.Second, |
|
Transport: &http.Transport{ |
|
DisableKeepAlives: true, |
|
}, |
|
} |
|
req.Close = true |
|
log.Debug("req:%+v", req) |
|
resp, err := client.Do(req) |
|
if err != nil { |
|
log.Error("http post call err:%v", err) |
|
return 1 |
|
} |
|
defer resp.Body.Close() |
|
body, _ := ioutil.ReadAll(resp.Body) |
|
log.Debug("response Body:%v", string(body)) |
|
if err := json.Unmarshal(body, ret); err != nil { |
|
log.Error("unmarshal fail err:%v", err) |
|
return 1 |
|
} |
|
return 0 |
|
}
|
|
|