Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
lmxdawn committed Jan 18, 2022
1 parent 2fb84d6 commit b7c9bb7
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type HttpClient struct {
coinName string
rechargeNotifyUrl string
withdrawNotifyUrl string
timeout int // 超时时间,毫秒单位
client *http.Client
}

// NewHttpClient 创建
Expand All @@ -35,7 +35,9 @@ func NewHttpClient(protocol, coinName, rechargeNotifyUrl, withdrawNotifyUrl stri
coinName,
rechargeNotifyUrl,
withdrawNotifyUrl,
1000 * 10,
&http.Client{
Timeout: time.Millisecond * time.Duration(10*1000),
},
}
}

Expand Down Expand Up @@ -100,15 +102,12 @@ func (h *HttpClient) get(urlStr string, params url.Values, res interface{}) erro
Url.RawQuery = params.Encode()
urlPath := Url.String()

client := &http.Client{
Timeout: time.Millisecond * time.Duration(h.timeout),
}
req, err := http.NewRequest(http.MethodGet, urlPath, nil)
if err != nil {
// handle error
return err
}
resp, err := client.Do(req)
resp, err := h.client.Do(req)
if err != nil {
// handle error
return err
Expand All @@ -135,16 +134,13 @@ func (h *HttpClient) post(urlStr string, data map[string]interface{}, res interf
return err
}

client := &http.Client{
Timeout: time.Millisecond * time.Duration(h.timeout),
}
req, err := http.NewRequest(http.MethodPost, urlStr, bytes.NewReader(bytesData))
if err != nil {
// handle error
return err
}
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
resp, err := h.client.Do(req)
if err != nil {
// handle error
return err
Expand Down

0 comments on commit b7c9bb7

Please sign in to comment.