feat: 新增数据库导出功能&其他小优化

This commit is contained in:
meilin.huang
2022-06-30 16:42:25 +08:00
parent 64b49dae2e
commit fe8cd93c78
11 changed files with 234 additions and 31 deletions

View File

@@ -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)
}
}