🔥 只初始化一次client
This commit is contained in:
@ -10,7 +10,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"crypto/tls"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// convert body to json
|
// convert body to json
|
||||||
@ -62,13 +61,8 @@ func DoPost(url string, request interface{}, auth string) (body []byte, err erro
|
|||||||
req.Header.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
|
req.Header.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
|
||||||
req.Header.Add("Connection", "keep-alive")
|
req.Header.Add("Connection", "keep-alive")
|
||||||
|
|
||||||
tr := &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
||||||
}
|
|
||||||
client := &http.Client{Transport: tr}
|
|
||||||
|
|
||||||
for retryCount := 3; retryCount >= 0; retryCount-- {
|
for retryCount := 3; retryCount >= 0; retryCount-- {
|
||||||
if resp, err = client.Do(req); err != nil && strings.Contains(err.Error(), "timeout") {
|
if resp, err = conf.Client.Do(req); err != nil && strings.Contains(err.Error(), "timeout") {
|
||||||
<-time.After(time.Second)
|
<-time.After(time.Second)
|
||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
@ -84,4 +78,3 @@ func DoPost(url string, request interface{}, auth string) (body []byte, err erro
|
|||||||
log.Debugf("请求返回信息:%s", string(body))
|
log.Debugf("请求返回信息:%s", string(body))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package bootstrap
|
package bootstrap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -9,5 +10,8 @@ import (
|
|||||||
// init request client
|
// init request client
|
||||||
func InitClient() {
|
func InitClient() {
|
||||||
log.Infof("初始化client...")
|
log.Infof("初始化client...")
|
||||||
conf.Client = &http.Client{}
|
tr := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
|
}
|
||||||
|
conf.Client = &http.Client{Transport: tr}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user