- refactor.

This commit is contained in:
gazebo
2018-06-12 14:06:11 +08:00
parent 35e46f7563
commit 94fd9c3e60
3 changed files with 85 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ package utils
import (
"bytes"
"encoding/json"
"fmt"
"reflect"
"strconv"
)
@@ -86,6 +87,15 @@ func UnmarshalUseNumber(data []byte, result interface{}) error {
return d.Decode(result)
}
func MustMarshal(obj interface{}) []byte {
byteArr, err := json.Marshal(obj)
if err != nil {
panic(fmt.Sprintf("err when Marshal obj:%v", obj))
}
return byteArr
}
func Bool2String(value bool) string {
if value {
return "true"
@@ -102,3 +112,11 @@ func Str2Int64(str string) int64 {
retVal, _ := strconv.ParseInt(str, 10, 64)
return retVal
}
func Int64ToStr(value int64) string {
return strconv.FormatInt(value, 10)
}
func Int2Str(value int) string {
return strconv.Itoa(value)
}