- use Must func when possible.

This commit is contained in:
gazebo
2018-06-14 09:54:19 +08:00
parent 5f6865666a
commit 9696e142ee
5 changed files with 76 additions and 12 deletions

View File

@@ -2,7 +2,6 @@ package elmapi
import (
"crypto/md5"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
@@ -37,7 +36,7 @@ var (
type ELMResult struct {
Id string
Result map[string]interface{}
Result interface{}
Error map[string]interface{}
}
@@ -85,7 +84,7 @@ func (e *ELMAPI) signParams(action string, payload *ELMPayload) string {
}
for _, data := range allData {
for k, v := range data {
vBytes, _ := json.Marshal(v)
vBytes := utils.MustMarshal(v)
keyValues = append(keyValues, k+"="+string(vBytes))
}
}
@@ -102,7 +101,7 @@ func (e *ELMAPI) AccessELM(action string, params map[string]interface{}) (*ELMRe
}
metas := map[string]interface{}{
"app_key": e.appKey,
"timestamp": int(utils.GetCurTimestamp()),
"timestamp": utils.GetCurTimestamp(),
}
payload := &ELMPayload{
@@ -115,11 +114,8 @@ func (e *ELMAPI) AccessELM(action string, params map[string]interface{}) (*ELMRe
}
payload.Signature = e.signParams(action, payload)
dataBytes, err := json.Marshal(payload)
if err != nil {
e.sugarLogger.Errorf("Error when marshal %v, error:%v", payload, err)
return nil, err
}
dataBytes := utils.MustMarshal(payload)
dataStr := string(dataBytes)
exceedLimitRetryCount := 0
systemErrorRetryCount := 0
@@ -162,11 +158,10 @@ func (e *ELMAPI) AccessELM(action string, params map[string]interface{}) (*ELMRe
jsonResult1, err := utils.HttpResponse2Json(response)
resultError, _ := jsonResult1["error"].(map[string]interface{})
result, _ := jsonResult1["result"].(map[string]interface{})
jsonResult := &ELMResult{
Id: jsonResult1["id"].(string),
Error: resultError,
Result: result,
Result: jsonResult1["result"],
}
if err != nil {
e.sugarLogger.Warnf("HttpResponse2Json return:%v", err)