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

38 lines
826 B
Go

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,
}
}