finclip-app-manager/infrastructure/go-resty/go_resty.go

38 lines
826 B
Go
Raw Normal View History

2023-10-31 14:07:26 +08:00
package goResty
import (
"net"
"net/http"
"time"
"github.com/go-resty/resty/v2"
)
var headers = map[string]string{
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
}
var RestyClient = resty.NewWithClient(&http.Client{
Transport: createTransport(nil),
})
func createTransport(localAddr net.Addr) *http.Transport {
dialer := &net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}
if localAddr != nil {
dialer.LocalAddr = localAddr
}
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: dialer.DialContext,
MaxIdleConns: 200,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
MaxIdleConnsPerHost: 200,
}
}