记录:数据类型转换
func ToString(value interface{}) string {
var str string
if value == nil {
return str
}
switch t := value.(type) {
case float64:
str = strconv.FormatFloat(t, 'f', -1, bitSize)
case float32:
str = strconv.FormatFloat(float64(t), 'f', -1, bitSize)
case int:
str = strconv.Itoa(t)
case uint:
str = strconv.Itoa(int(t))
case int8:
str = strconv.Itoa(int(t))
case uint8:
str = strconv.Itoa(int(t))
case int16:
str = strconv.Itoa(int(t))
case uint16:
str = strconv.Itoa(int(t))
case int32:
str = strconv.Itoa(int(t))
case uint32:
str = strconv.Itoa(int(t))
case int64:
str = strconv.FormatInt(t, base)
case uint64:
str = strconv.FormatUint(t, base)
case string:
str = value.(string)
case []byte:
str = string(value.([]byte))
default:
newValue, _ := json.Marshal(value)
str = string(newValue)
}
return str
}