- make sugarLogger baseapi globals.

This commit is contained in:
gazebo
2018-06-20 15:51:37 +08:00
parent 55df9f7a2f
commit 21773180a2
7 changed files with 49 additions and 55 deletions

View File

@@ -6,8 +6,8 @@ import (
"net/http"
"time"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/utils"
"go.uber.org/zap"
)
type AccessPlatformAPIWithRetryParams struct {
@@ -16,7 +16,6 @@ type AccessPlatformAPIWithRetryParams struct {
SleepSecondWhenExceedLimit time.Duration
Client *http.Client
Request *http.Request
SugarLogger *zap.SugaredLogger
}
const (
@@ -47,7 +46,7 @@ func AccessPlatformAPIWithRetry(params *AccessPlatformAPIWithRetryParams, handle
for {
response, err := params.Client.Do(params.Request)
if err != nil {
params.SugarLogger.Debugf("client.Get return err:%v", err)
baseapi.SugarLogger.Debugf("client.Get return err:%v", err)
err, ok := err.(net.Error)
recoverableErrorRetryCount++
if ok && err.Timeout() && recoverableErrorRetryCount <= params.MaxRecoverableRetryCount {
@@ -58,7 +57,7 @@ func AccessPlatformAPIWithRetry(params *AccessPlatformAPIWithRetryParams, handle
}
defer response.Body.Close()
if response.StatusCode != 200 {
params.SugarLogger.Debugf("http code is:%d", response.StatusCode)
baseapi.SugarLogger.Debugf("http code is:%d", response.StatusCode)
recoverableErrorRetryCount++
if recoverableErrorRetryCount <= params.MaxRecoverableRetryCount {
continue