This commit is contained in:
2025-11-02 20:33:28 +08:00
parent bb88c78c82
commit 2773c1a60b
13 changed files with 521 additions and 132 deletions

View File

@@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"strings"
"time"
)
var (
@@ -58,10 +59,27 @@ func (a *AlicloudService) CallAPI(path string, params map[string]interface{}) (r
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
req.Header.Set("Authorization", "APPCODE "+a.config.AppCode)
// 发送请求
client := &http.Client{}
// 发送请求超时时间设置为60秒
client := &http.Client{
Timeout: 60 * time.Second,
}
resp, err := client.Do(req)
if err != nil {
// 检查是否是超时错误
isTimeout := false
if netErr, ok := err.(interface{ Timeout() bool }); ok && netErr.Timeout() {
isTimeout = true
} else if errStr := err.Error();
errStr == "context deadline exceeded" ||
errStr == "timeout" ||
errStr == "Client.Timeout exceeded" ||
errStr == "net/http: request canceled" {
isTimeout = true
}
if isTimeout {
return nil, fmt.Errorf("%w: API请求超时: %s", ErrDatasource, err.Error())
}
return nil, fmt.Errorf("%w: %s", ErrSystem, err.Error())
}
defer resp.Body.Close()