- 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

@@ -10,9 +10,9 @@ import (
"strings"
"time"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/platform/common"
"git.rosy.net.cn/baseapi/utils"
"go.uber.org/zap"
)
const (
@@ -35,12 +35,11 @@ type ELMResult struct {
}
type ELMAPI struct {
token string
appKey string
secret string
sugarLogger *zap.SugaredLogger
url *url.URL
client *http.Client
token string
appKey string
secret string
url *url.URL
client *http.Client
}
type ELMPayload struct {
@@ -53,13 +52,12 @@ type ELMPayload struct {
Signature string `json:"signature"`
}
func NewELMAPI(token, appKey, secret string, sugarLogger *zap.SugaredLogger, isProd bool) *ELMAPI {
func NewELMAPI(token, appKey, secret string, isProd bool) *ELMAPI {
api := &ELMAPI{
token: token,
appKey: appKey,
secret: secret,
sugarLogger: sugarLogger,
client: &http.Client{Timeout: clientTimeout},
token: token,
appKey: appKey,
secret: secret,
client: &http.Client{Timeout: clientTimeout},
}
if isProd {
@@ -87,7 +85,7 @@ func (e *ELMAPI) signParamsMap(mapData map[string]interface{}, prefix string) st
sort.Strings(keyValues)
finalStr := prefix + strings.Join(keyValues, "") + e.secret
// e.sugarLogger.Debugf("sign str:%v", finalStr)
// baseapi.SugarLogger.Debugf("sign str:%v", finalStr)
return fmt.Sprintf("%X", md5.Sum([]byte(finalStr)))
}
@@ -133,13 +131,12 @@ func (e *ELMAPI) AccessELM(action string, params map[string]interface{}) (retVal
Body: ioutil.NopCloser(strings.NewReader(string(utils.MustMarshal(payload)))),
},
SugarLogger: e.sugarLogger,
}
err = common.AccessPlatformAPIWithRetry(apiAccess, func(response *http.Response) (result string, err error) {
jsonResult1, err := utils.HttpResponse2Json(response)
if err != nil {
e.sugarLogger.Warnf("HttpResponse2Json return:%v", err)
baseapi.SugarLogger.Warnf("HttpResponse2Json return:%v", err)
return common.PAErrorLevelGeneralFail, err
}
resultError, _ := jsonResult1["error"].(map[string]interface{})