- fix retry bug (request can not be reused).

This commit is contained in:
gazebo
2018-08-15 22:06:57 +08:00
parent fa83668d82
commit 47e1b3989d
11 changed files with 65 additions and 40 deletions

View File

@@ -4,6 +4,7 @@ import (
"errors"
"net"
"net/http"
"strings"
"time"
"github.com/fatih/structs"
@@ -72,10 +73,19 @@ func init() {
structs.DefaultTagName = "json"
}
func AccessPlatformAPIWithRetry(client *http.Client, request *http.Request, config *APIConfig, handleResponse func(response *http.Response) (string, error)) error {
func AccessPlatformAPIWithRetry(client *http.Client, method, requestURL, body string, header http.Header, config *APIConfig, handleResponse func(response *http.Response) (string, error)) error {
exceedLimitRetryCount := 0
recoverableErrorRetryCount := 0
var request *http.Request
for {
if body != "" {
request, _ = http.NewRequest(method, requestURL, strings.NewReader(body))
} else {
request, _ = http.NewRequest(method, requestURL, nil)
}
if header != nil {
request.Header = header
}
response, err := client.Do(request)
if err != nil {
baseapi.SugarLogger.Debugf("AccessPlatformAPIWithRetry client.Get return err:%v", err)