- big big refactor.

This commit is contained in:
gazebo
2018-06-22 22:26:12 +08:00
parent 062f7a2540
commit 7657966da5
27 changed files with 1277 additions and 1266 deletions

View File

@@ -92,7 +92,11 @@ func DictKeysMan(data interface{}, keysToRemove []string, keysToKeep []string) i
func UnmarshalUseNumber(data []byte, result interface{}) error {
d := json.NewDecoder(bytes.NewReader(data))
d.UseNumber()
return d.Decode(result)
err := d.Decode(result)
if err != nil {
baseapi.SugarLogger.Errorf("decode data:%v, error:%v", string(data), err)
}
return err
}
func MustMarshal(obj interface{}) []byte {
@@ -112,12 +116,18 @@ func Bool2String(value bool) string {
}
func Str2Int(str string) int {
retVal, _ := strconv.Atoi(str)
retVal, err := strconv.Atoi(str)
if err != nil {
baseapi.SugarLogger.Errorf("error when convert %s to int", str)
}
return retVal
}
func Str2Int64(str string) int64 {
retVal, _ := strconv.ParseInt(str, 10, 64)
retVal, err := strconv.ParseInt(str, 10, 64)
if err != nil {
baseapi.SugarLogger.Errorf("error when convert %s to int64", str)
}
return retVal
}
@@ -150,15 +160,15 @@ func Timestamp2Str(timestamp int64) string {
return time.Unix(timestamp/1000, 0).Format("2006-01-02 15:04:05")
}
func HttpResponse2Json(response *http.Response) (map[string]interface{}, error) {
func HTTPResponse2Json(response *http.Response) (map[string]interface{}, error) {
var jsonResult map[string]interface{}
bodyData, err := ioutil.ReadAll(response.Body)
if err != nil {
baseapi.SugarLogger.Errorf("ioutil.ReadAll error:%v", err)
return nil, err
}
err = UnmarshalUseNumber(bodyData, &jsonResult)
if err != nil {
if err = UnmarshalUseNumber(bodyData, &jsonResult); err != nil {
return nil, err
}
return jsonResult, nil