You've already forked VptPassiveAdapter
41 lines
874 B
Go
41 lines
874 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
// 通用HTTP客户端,带短超时时间,适用于API调用
|
|
apiClient = &http.Client{
|
|
Transport: &http.Transport{
|
|
MaxIdleConns: 100,
|
|
MaxIdleConnsPerHost: 10,
|
|
IdleConnTimeout: 90 * time.Second,
|
|
DisableKeepAlives: false,
|
|
},
|
|
Timeout: 5 * time.Second,
|
|
}
|
|
|
|
// 文件上传专用HTTP客户端,超时时间较长
|
|
uploadClient = &http.Client{
|
|
Transport: &http.Transport{
|
|
MaxIdleConns: 50,
|
|
MaxIdleConnsPerHost: 5,
|
|
IdleConnTimeout: 90 * time.Second,
|
|
DisableKeepAlives: false,
|
|
},
|
|
Timeout: 60 * time.Second, // 文件上传需要更长的超时时间
|
|
}
|
|
)
|
|
|
|
// GetAPIClient 获取API调用客户端
|
|
func GetAPIClient() *http.Client {
|
|
return apiClient
|
|
}
|
|
|
|
// GetUploadClient 获取文件上传客户端
|
|
func GetUploadClient() *http.Client {
|
|
return uploadClient
|
|
}
|