Compare commits
No commits in common. "0a9175daa8ecdb3112280732a73ab302973eda9c" and "c641e6003bae5a296feee7ee377e60e26917e755" have entirely different histories.
0a9175daa8
...
c641e6003b
90
any.go
90
any.go
@ -7,10 +7,7 @@
|
||||
// Date : 2023-06-01 18:18
|
||||
package wrapper
|
||||
|
||||
import (
|
||||
"git.zhangdeman.cn/zhangdeman/serialize"
|
||||
"reflect"
|
||||
)
|
||||
import "reflect"
|
||||
|
||||
// AnyDataType ...
|
||||
//
|
||||
@ -18,11 +15,9 @@ import (
|
||||
//
|
||||
// Date : 18:19 2023/6/1
|
||||
func AnyDataType(data interface{}) *AnyType {
|
||||
at := &AnyType{
|
||||
return &AnyType{
|
||||
data: data,
|
||||
}
|
||||
at.dataType = at.Type()
|
||||
return at
|
||||
}
|
||||
|
||||
// AnyType ...
|
||||
@ -31,8 +26,7 @@ func AnyDataType(data interface{}) *AnyType {
|
||||
//
|
||||
// Date : 18:19 2023/6/1
|
||||
type AnyType struct {
|
||||
data interface{}
|
||||
dataType string
|
||||
data interface{}
|
||||
}
|
||||
|
||||
// IsNil 是否为 nil
|
||||
@ -50,33 +44,23 @@ func (at *AnyType) IsNil() bool {
|
||||
//
|
||||
// Date : 18:22 2023/6/1
|
||||
func (at *AnyType) Type() string {
|
||||
if len(at.dataType) > 0 {
|
||||
// 已经处理过的,无需在处理
|
||||
return at.dataType
|
||||
}
|
||||
if at.IsNil() {
|
||||
return DataTypeNil
|
||||
}
|
||||
reflectType := reflect.TypeOf(at.data)
|
||||
switch reflectType.Kind() {
|
||||
case reflect.String:
|
||||
return DataTypeString
|
||||
case reflect.Slice, reflect.Array:
|
||||
return DataTypeSlice
|
||||
case reflect.Map, reflect.Struct:
|
||||
return DataTypeObject
|
||||
case reflect.Slice:
|
||||
return DataTypeAnySlice
|
||||
case reflect.Array:
|
||||
return DataTypeAnySlice
|
||||
case reflect.Map:
|
||||
return DataTypeAnyObject
|
||||
case reflect.Struct:
|
||||
return DataTypeAnyObject
|
||||
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 DataTypeUnknown
|
||||
return reflectType.Kind().String()
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,52 +69,6 @@ func (at *AnyType) Type() string {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:32 2023/6/1
|
||||
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 String("")
|
||||
}
|
||||
|
||||
// ToObject 任意类型转为对象
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:19 2023/10/11
|
||||
func (at *AnyType) ToObject() MapResult {
|
||||
return MapResult{
|
||||
Value: EasyMapFromString(at.ToString().Value()),
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func (at *AnyType) ToIntSlice() {
|
||||
|
||||
}
|
||||
|
||||
func (at *AnyType) ToUintSlice() {
|
||||
|
||||
}
|
||||
|
||||
func (at *AnyType) ToStringSlice() {
|
||||
|
||||
}
|
||||
|
||||
func (at *AnyType) ToFloatSlice() {
|
||||
|
||||
}
|
||||
|
||||
func (at *AnyType) ToBoolSlice() {
|
||||
|
||||
}
|
||||
|
||||
func (at *AnyType) ToAnySlice() {
|
||||
|
||||
func (at *AnyType) ToString() string {
|
||||
return ""
|
||||
}
|
||||
|
39
define.go
39
define.go
@ -12,14 +12,41 @@ import "time"
|
||||
const (
|
||||
DataTypeUnknown = "unknown"
|
||||
DataTypeNil = "nil"
|
||||
DataTypeAny = "interface"
|
||||
DataTypePtr = "ptr"
|
||||
DataTypeString = "string"
|
||||
DataTypeInt = "int"
|
||||
DataTypeUint = "uint"
|
||||
DataTypeBool = "bool"
|
||||
|
||||
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"
|
||||
DataTypeFloat = "float"
|
||||
DataTypeSlice = "slice"
|
||||
DataTypeObject = "object"
|
||||
|
||||
DataTypeIntSlice = "[]int"
|
||||
DataTypeUntSlice = "[]uint"
|
||||
DataTypeNumberSlice = "[]number"
|
||||
DataTypeFloatSlice = "[]float"
|
||||
DataTypeBoolSlice = "[]bool"
|
||||
DataTypeAnySlice = "[]interface"
|
||||
|
||||
DataTypeObject = "map[string]interface"
|
||||
DataTypeAnyObject = "map[interface]interface"
|
||||
)
|
||||
|
||||
// Int8Result ...
|
||||
|
Loading…
Reference in New Issue
Block a user