增加获取各种数据类型的默认值方法
This commit is contained in:
parent
734d9a9f77
commit
d6e86b64f7
96
data_type.go
96
data_type.go
@ -312,117 +312,117 @@ func getMergeDataTypeList(dataTypeList ...[]DataType) []DataType {
|
||||
}
|
||||
|
||||
// GetDataTypeDefaultValue 获取不同类型的默认值
|
||||
func GetDataTypeDefaultValue(dataType string) any {
|
||||
func GetDataTypeDefaultValue(dataType DataType) any {
|
||||
switch dataType {
|
||||
case DataTypeInt.String():
|
||||
case DataTypeInt:
|
||||
return int(0)
|
||||
case DataTypeInt8.String():
|
||||
case DataTypeInt8:
|
||||
return int8(0)
|
||||
case DataTypeInt16.String():
|
||||
case DataTypeInt16:
|
||||
return int16(0)
|
||||
case DataTypeInt32.String():
|
||||
case DataTypeInt32:
|
||||
return int32(0)
|
||||
case DataTypeInt64.String():
|
||||
case DataTypeInt64:
|
||||
return int64(0)
|
||||
case DataTypeUint.String():
|
||||
case DataTypeUint:
|
||||
return uint(0)
|
||||
case DataTypeUint8.String():
|
||||
case DataTypeUint8:
|
||||
return uint8(0)
|
||||
case DataTypeUint16.String():
|
||||
case DataTypeUint16:
|
||||
return uint16(0)
|
||||
case DataTypeUint32.String():
|
||||
case DataTypeUint32:
|
||||
return uint32(0)
|
||||
case DataTypeUint64.String():
|
||||
case DataTypeUint64:
|
||||
return uint64(0)
|
||||
case DataTypeFloat32.String():
|
||||
case DataTypeFloat32:
|
||||
return float32(0)
|
||||
case DataTypeFloat64.String():
|
||||
case DataTypeFloat64:
|
||||
return float64(0)
|
||||
case DataTypeBool.String():
|
||||
case DataTypeBool:
|
||||
return false
|
||||
case DataTypeString.String():
|
||||
case DataTypeString:
|
||||
return ""
|
||||
case DataTypeIntPtr.String():
|
||||
case DataTypeIntPtr:
|
||||
return new(int)
|
||||
case DataTypeInt8Ptr.String():
|
||||
case DataTypeInt8Ptr:
|
||||
return new(int8)
|
||||
case DataTypeInt16Ptr.String():
|
||||
case DataTypeInt16Ptr:
|
||||
return new(int16)
|
||||
case DataTypeInt32Ptr.String():
|
||||
case DataTypeInt32Ptr:
|
||||
return new(int32)
|
||||
case DataTypeInt64Ptr.String():
|
||||
case DataTypeInt64Ptr:
|
||||
return new(int64)
|
||||
case DataTypeUintPtr.String():
|
||||
case DataTypeUintPtr:
|
||||
return new(uint)
|
||||
case DataTypeUint8Ptr.String():
|
||||
case DataTypeUint8Ptr:
|
||||
return new(uint8)
|
||||
case DataTypeUint16Ptr.String():
|
||||
case DataTypeUint16Ptr:
|
||||
return new(uint16)
|
||||
case DataTypeUint32Ptr.String():
|
||||
case DataTypeUint32Ptr:
|
||||
return new(uint32)
|
||||
case DataTypeUint64Ptr.String():
|
||||
case DataTypeUint64Ptr:
|
||||
return new(uint64)
|
||||
case DataTypeFloat32Ptr.String():
|
||||
case DataTypeFloat32Ptr:
|
||||
return new(float32)
|
||||
case DataTypeFloat64Ptr.String():
|
||||
case DataTypeFloat64Ptr:
|
||||
return new(float64)
|
||||
case DataTypeBoolPtr.String():
|
||||
case DataTypeBoolPtr:
|
||||
return new(bool)
|
||||
case DataTypeMapStrAny.String():
|
||||
case DataTypeMapStrAny:
|
||||
return new(map[string]any)
|
||||
case DataTypeMapAnyAny.String():
|
||||
case DataTypeMapAnyAny:
|
||||
return new(map[any]any)
|
||||
case DataTypeMapStrBool.String():
|
||||
case DataTypeMapStrBool:
|
||||
return new(map[string]bool)
|
||||
case DataTypeMapStrInt.String():
|
||||
case DataTypeMapStrInt:
|
||||
return new(map[string]int)
|
||||
case DataTypeMapStrFloat.String():
|
||||
case DataTypeMapStrFloat:
|
||||
return new(map[string]float64)
|
||||
case DataTypeMapStrUint.String():
|
||||
case DataTypeMapStrUint:
|
||||
return new(map[string]uint)
|
||||
case DataTypeMapStrSlice.String():
|
||||
case DataTypeMapStrSlice:
|
||||
return new(map[string][]any)
|
||||
case DataTypeMapStrStr.String():
|
||||
case DataTypeMapStrStr:
|
||||
return new(map[string]string)
|
||||
case DataTypeSliceAny.String():
|
||||
case DataTypeSliceAny:
|
||||
return new([]any)
|
||||
case DataTypeSliceString.String():
|
||||
case DataTypeSliceString:
|
||||
return new([]string)
|
||||
case DataTypeSliceBool.String():
|
||||
case DataTypeSliceBool:
|
||||
return new([]bool)
|
||||
case DataTypeSliceInt.String():
|
||||
case DataTypeSliceInt:
|
||||
return new([]int)
|
||||
case DataTypeSliceUint.String():
|
||||
case DataTypeSliceUint:
|
||||
return new([]uint)
|
||||
case DataTypeSliceFloat.String():
|
||||
case DataTypeSliceFloat:
|
||||
return new([]float64)
|
||||
case DataTypeSliceMapAnyAny.String():
|
||||
case DataTypeSliceMapAnyAny:
|
||||
// map[any]any 序列化会有问题,当做 map[string]any 处理
|
||||
return new([]map[string]any)
|
||||
case DataTypeSliceMapStringAny.String():
|
||||
case DataTypeSliceMapStringAny:
|
||||
return new([]map[string]any)
|
||||
default:
|
||||
// 序列化之后的map
|
||||
for _, dataTypeItem := range DataTypeMapMarshal {
|
||||
if dataTypeItem.String() == dataType {
|
||||
if dataTypeItem == dataType {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
// 序列化之后的slice
|
||||
for _, dataTypeItem := range DataTypeSliceMarshal {
|
||||
if dataTypeItem.String() == dataType {
|
||||
if dataTypeItem == dataType {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
// 指定分隔符分割的slice
|
||||
for _, dataTypeItem := range DataTypeSliceSplit {
|
||||
if dataTypeItem.String() == dataType {
|
||||
if dataTypeItem == dataType {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
// 未枚举的slice类型用any接收
|
||||
for _, dataTypeItem := range DataTypeSlice {
|
||||
if dataTypeItem.String() == dataType {
|
||||
if dataTypeItem == dataType {
|
||||
return new([]any)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user