2021-03-31 07:29:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2021-06-14 19:34:29 +00:00
|
|
|
type httpClient interface {
|
|
|
|
Do(req *http.Request) (*http.Response, error)
|
|
|
|
}
|
|
|
|
|
2021-11-08 13:32:02 +00:00
|
|
|
type appHttpClient struct {
|
|
|
|
hc *http.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ httpClient = &appHttpClient{}
|
|
|
|
|
|
|
|
func (c *appHttpClient) Do(req *http.Request) (*http.Response, error) {
|
|
|
|
if c.hc == nil {
|
|
|
|
c.hc = &http.Client{
|
|
|
|
Timeout: 5 * time.Minute,
|
|
|
|
Transport: &http.Transport{
|
|
|
|
DisableKeepAlives: true,
|
|
|
|
},
|
|
|
|
}
|
2021-06-19 06:37:16 +00:00
|
|
|
}
|
2021-11-08 13:32:02 +00:00
|
|
|
return c.hc.Do(req)
|
2021-06-19 06:37:16 +00:00
|
|
|
}
|