GoBlog/httpClient.go

29 lines
447 B
Go
Raw Normal View History

2021-03-31 07:29:52 +00:00
package main
import (
"net/http"
"time"
)
type httpClient interface {
Do(req *http.Request) (*http.Response, error)
}
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
}
return c.hc.Do(req)
2021-06-19 06:37:16 +00:00
}