- use Must func when possible.
This commit is contained in:
@@ -144,6 +144,10 @@ func GetAPIOperator() string {
|
||||
return time.Now().Format("2006-01-02_15:04:05")
|
||||
}
|
||||
|
||||
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) {
|
||||
var jsonResult map[string]interface{}
|
||||
bodyData, err := ioutil.ReadAll(response.Body)
|
||||
@@ -157,3 +161,15 @@ func HttpResponse2Json(response *http.Response) (map[string]interface{}, error)
|
||||
}
|
||||
return jsonResult, nil
|
||||
}
|
||||
|
||||
func MustInterface2Int64(data interface{}) int64 {
|
||||
dataNumber, ok := data.(json.Number)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("error when convert:%v", data))
|
||||
}
|
||||
retVal, err := dataNumber.Int64()
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user