finclip-app-manager/vendor/gitlab.finogeeks.club/finclip-backend/mop-middleware-auth/grpc/go-resty.go

38 lines
823 B
Go
Raw Permalink Normal View History

2023-11-02 18:36:36 +08:00
package grpc
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,
}
}