mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-27 03:20:25 +08:00
feat: 新增数据库导出功能&其他小优化
This commit is contained in:
@@ -2,6 +2,8 @@ package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
@@ -107,3 +109,45 @@ func ReverStrTemplate(temp, str string, res map[string]interface{}) {
|
||||
ReverStrTemplate(next, StrTrim(SubString(str, UnicodeIndex(str, value)+StrLen(value), StrLen(str))), res)
|
||||
}
|
||||
}
|
||||
|
||||
func ToString(value interface{}) string {
|
||||
// interface 转 string
|
||||
var key string
|
||||
if value == nil {
|
||||
return key
|
||||
}
|
||||
|
||||
switch it := value.(type) {
|
||||
case float64:
|
||||
return strconv.FormatFloat(it, 'f', -1, 64)
|
||||
case float32:
|
||||
return strconv.FormatFloat(float64(it), 'f', -1, 64)
|
||||
case int:
|
||||
return strconv.Itoa(it)
|
||||
case uint:
|
||||
return strconv.Itoa(int(it))
|
||||
case int8:
|
||||
return strconv.Itoa(int(it))
|
||||
case uint8:
|
||||
return strconv.Itoa(int(it))
|
||||
case int16:
|
||||
return strconv.Itoa(int(it))
|
||||
case uint16:
|
||||
return strconv.Itoa(int(it))
|
||||
case int32:
|
||||
return strconv.Itoa(int(it))
|
||||
case uint32:
|
||||
return strconv.Itoa(int(it))
|
||||
case int64:
|
||||
return strconv.FormatInt(it, 10)
|
||||
case uint64:
|
||||
return strconv.FormatUint(it, 10)
|
||||
case string:
|
||||
return it
|
||||
case []byte:
|
||||
return string(value.([]byte))
|
||||
default:
|
||||
newValue, _ := json.Marshal(value)
|
||||
return string(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user