🐛
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @Author: fuxiao
|
||||
* @Email: 576101059@qq.com
|
||||
* @Author: Echo
|
||||
* @Email: 1711788888@qq.com
|
||||
* @Date: 2021/8/26 5:00 下午
|
||||
* @Desc: TODO
|
||||
*/
|
||||
@@ -68,20 +68,20 @@ func String(any interface{}) string {
|
||||
if v == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
|
||||
if i, ok := v.(stringInterface); ok {
|
||||
return i.String()
|
||||
}
|
||||
|
||||
|
||||
if i, ok := v.(errorInterface); ok {
|
||||
return i.Error()
|
||||
}
|
||||
|
||||
|
||||
var (
|
||||
rv = reflect.ValueOf(v)
|
||||
kind = rv.Kind()
|
||||
)
|
||||
|
||||
|
||||
switch kind {
|
||||
case reflect.Chan,
|
||||
reflect.Map,
|
||||
@@ -96,11 +96,11 @@ func String(any interface{}) string {
|
||||
case reflect.String:
|
||||
return rv.String()
|
||||
}
|
||||
|
||||
|
||||
if kind == reflect.Ptr {
|
||||
return String(rv.Elem().Interface())
|
||||
}
|
||||
|
||||
|
||||
if b, e := json.Marshal(v); e != nil {
|
||||
return fmt.Sprint(v)
|
||||
} else {
|
||||
@@ -211,16 +211,16 @@ func Scan(b []byte, any interface{}) error {
|
||||
rv = reflect.ValueOf(v)
|
||||
kind = rv.Kind()
|
||||
)
|
||||
|
||||
|
||||
if kind != reflect.Ptr {
|
||||
return fmt.Errorf("can't unmarshal %T", v)
|
||||
}
|
||||
|
||||
|
||||
switch kind = rv.Elem().Kind(); kind {
|
||||
case reflect.Array, reflect.Slice, reflect.Map, reflect.Struct:
|
||||
return json.Unmarshal(b, v)
|
||||
}
|
||||
|
||||
|
||||
return fmt.Errorf("can't unmarshal %T", v)
|
||||
}
|
||||
}
|
||||
@@ -231,4 +231,4 @@ func UnsafeStringToBytes(s string) []byte {
|
||||
|
||||
func UnsafeBytesToString(b []byte) string {
|
||||
return *(*string)(unsafe.Pointer(&b))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user