优化数据类型获取
This commit is contained in:
parent
8b1a515cb9
commit
160f464d15
44
any.go
44
any.go
@ -7,7 +7,10 @@
|
||||
// Date : 2023-06-01 18:18
|
||||
package wrapper
|
||||
|
||||
import "reflect"
|
||||
import (
|
||||
"git.zhangdeman.cn/zhangdeman/serialize"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// AnyDataType ...
|
||||
//
|
||||
@ -18,7 +21,7 @@ func AnyDataType(data interface{}) *AnyType {
|
||||
at := &AnyType{
|
||||
data: data,
|
||||
}
|
||||
at.Type()
|
||||
at.dataType = at.Type()
|
||||
return at
|
||||
}
|
||||
|
||||
@ -56,18 +59,24 @@ func (at *AnyType) Type() string {
|
||||
}
|
||||
reflectType := reflect.TypeOf(at.data)
|
||||
switch reflectType.Kind() {
|
||||
case reflect.Slice:
|
||||
return DataTypeAnySlice
|
||||
case reflect.Array:
|
||||
return DataTypeAnySlice
|
||||
case reflect.Map:
|
||||
return DataTypeAnyObject
|
||||
case reflect.Struct:
|
||||
return DataTypeAnyObject
|
||||
case reflect.String:
|
||||
return DataTypeString
|
||||
case reflect.Slice, reflect.Array:
|
||||
return DataTypeSlice
|
||||
case reflect.Map, reflect.Struct:
|
||||
return DataTypeObject
|
||||
case reflect.Pointer:
|
||||
return DataTypePtr
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return DataTypeInt
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
return DataTypeUint
|
||||
case reflect.Bool:
|
||||
return DataTypeBool
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return DataTypeFloat
|
||||
default:
|
||||
return reflectType.Kind().String()
|
||||
return DataTypeUnknown
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +85,16 @@ func (at *AnyType) Type() string {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:32 2023/6/1
|
||||
func (at *AnyType) ToString() string {
|
||||
|
||||
func (at *AnyType) ToString() String {
|
||||
switch at.dataType {
|
||||
case DataTypeNil:
|
||||
return String("")
|
||||
case DataTypeObject:
|
||||
fallthrough
|
||||
case DataTypeSlice:
|
||||
fallthrough
|
||||
case DataTypePtr:
|
||||
return String(serialize.JSON.MarshalForString(at.data))
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
39
define.go
39
define.go
@ -12,41 +12,14 @@ import "time"
|
||||
const (
|
||||
DataTypeUnknown = "unknown"
|
||||
DataTypeNil = "nil"
|
||||
DataTypeAny = "interface"
|
||||
DataTypePtr = "ptr"
|
||||
|
||||
DataTypeString = "string"
|
||||
|
||||
DataTypeInt8 = "int8"
|
||||
DataTypeInt16 = "int16"
|
||||
DataTypeInt32 = "int32"
|
||||
DataTypeInt64 = "int64"
|
||||
DataTypeInt = "int"
|
||||
|
||||
DataTypeUint8 = "uint8"
|
||||
DataTypeUint16 = "uint16"
|
||||
DataTypeUint32 = "uint32"
|
||||
DataTypeUint64 = "uint64"
|
||||
DataTypeUint = "uint"
|
||||
|
||||
DataTypeBool = "bool"
|
||||
|
||||
DataTypeNumber = "number"
|
||||
|
||||
DataTypeFloat32 = "float32"
|
||||
DataTypeFloat64 = "float64"
|
||||
DataTypeDouble = "double"
|
||||
DataTypeString = "string"
|
||||
DataTypeInt = "int"
|
||||
DataTypeUint = "uint"
|
||||
DataTypeBool = "bool"
|
||||
DataTypeFloat = "float"
|
||||
|
||||
DataTypeIntSlice = "[]int"
|
||||
DataTypeUntSlice = "[]uint"
|
||||
DataTypeNumberSlice = "[]number"
|
||||
DataTypeFloatSlice = "[]float"
|
||||
DataTypeBoolSlice = "[]bool"
|
||||
DataTypeAnySlice = "[]interface"
|
||||
|
||||
DataTypeObject = "map[string]interface"
|
||||
DataTypeAnyObject = "map[interface]interface"
|
||||
DataTypeSlice = "slice"
|
||||
DataTypeObject = "object"
|
||||
)
|
||||
|
||||
// Int8Result ...
|
||||
|
Loading…
Reference in New Issue
Block a user