consts/data_type.go

264 lines
13 KiB
Go
Raw Normal View History

2024-04-08 16:35:10 +08:00
// Package consts ...
//
// Description : consts ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-04-08 16:33
package consts
2024-11-25 14:51:14 +08:00
// DataType 数据类型枚举值
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:10 2024/11/25
type DataType string
2025-01-22 15:55:39 +08:00
func (df *DataType) String() string {
return string(*df)
2024-11-25 14:51:14 +08:00
}
2025-01-22 15:55:39 +08:00
func (df *DataType) MarshalJSON() ([]byte, error) {
2024-11-25 14:51:14 +08:00
return []byte(df.String()), nil
}
// IsValid 判断枚举值是否有效
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:45 2024/11/25
2025-01-22 15:55:39 +08:00
func (df *DataType) IsValid() bool {
2024-11-25 14:51:14 +08:00
for _, item := range DataTypeList {
2025-01-22 15:55:39 +08:00
if item.Value == *df {
2024-11-25 14:51:14 +08:00
return true
}
}
return false
}
2025-02-07 20:56:48 +08:00
var (
2024-11-25 14:51:14 +08:00
DataTypeUnknown DataType = "unknown" // 位置数据类型
DataTypeNil DataType = "nil" // nil
DataTypePtr DataType = "ptr" // 指针
DataTypeInt DataType = "int" // int类型 -> int64
DataTypeUint DataType = "uint" // uint类型 -> uint64
DataTypeFloat DataType = "float" // float类型 -> float64
DataTypeBool DataType = "bool" // bool类型
DataTypeString DataType = "string" // 字符串类型
DataTypeSliceAny DataType = "[]any" // any数组 -> []any
DataTypeSliceAnyWithMarshal DataType = "[]any_marshal" // any数组 -> []any, json序列化之后的结构
DataTypeSliceInt DataType = "[]int" // int数组 -> []int64
DataTypeSliceIntWithChar DataType = "[]int_split" // int数组 -> []int64, 按照指定字符切割
DataTypeSliceIntWithMarshal DataType = "[]int_marshal" // int数组 -> []int64, json序列化之后的结果
DataTypeSliceUint DataType = "[]uint" // uint数组 -> []uint64
DataTypeSliceUintWithChar DataType = "[]uint_split" // uint数组 -> []uint64 指定字符切割
DataTypeSliceUintWithMarshal DataType = "[]uint_marshal" // uint数组 -> []uint64 json序列化之后的结果
DataTypeSliceFloat DataType = "[]float" // float数组 -> []float64
DataTypeSliceFloatWithChar DataType = "[]float_split" // float数组 -> []float64, 指定字符切割
DataTypeSliceFloatWithMarshal DataType = "[]float_marshal" // float数组 -> []float64, json序列化之后的结果
DataTypeSliceBool DataType = "[]bool" // bool数组 -> []bool
DataTypeSliceBoolWithChar DataType = "[]bool_split" // bool数组 -> []bool, 指定字符切割
DataTypeSliceBoolWithMarshal DataType = "[]bool_marshal" // bool数组 -> []bool, json序列化之后的结果
DataTypeSliceString DataType = "[]string" // 字符串数组 -> []string
DataTypeSliceStringWithChar DataType = "[]string_split" // 字符串数组 -> []string, 指定字符切割
DataTypeSliceStringWithMarshal DataType = "[]string_marshal" // 字符串数组 -> []string, json序列化之后的结果
DataTypeSliceSlice DataType = "[][]any" // 字符串数组 -> [][]any
DataTypeSliceSliceWithMarshal DataType = "[][]any_marshal" // 字符串数组 -> [][]any,json序列化之后的结果
DataTypeSliceMapAnyAny DataType = "[]map[any]any" // 字符串数组 -> []map[any]any, slice对象
DataTypeSliceMapAnyAnyWithMarshal DataType = "[]map[any]any_marshal" // 字符串数组 -> []map[any]any, json序列化后的结果
DataTypeSliceMapStringAny DataType = "[]map[string]any" // 字符串数组 -> map[string]any, slice对象
2025-02-07 20:56:48 +08:00
DataTypeSliceMapStringAnyWithMarshal DataType = "[]map[string]any_marshal" // 字符串数组 -> []map[string]any, slice对象, json序列化之后的结果
2024-11-25 14:51:14 +08:00
DataTypeMapStrInt DataType = "map[string]int" // map -> map[string]int64
DataTypeMapStrIntWithMarshal DataType = "map[string]int_marshal" // map -> map[string]int64,json序列化之后的结果
DataTypeMapStrUint DataType = "map[string]uint" // map -> map[string]uint64
DataTypeMapStrUintWithMarshal DataType = "map[string]uint_marshal" // map -> map[string]uint64, json序列化之后的结果
DataTypeMapStrFloat DataType = "map[string]float" // map -> map[string]float64
DataTypeMapStrFloatWithMarshal DataType = "map[string]float_marshal" // map -> map[string]float64, json序列化之后的结果
DataTypeMapStrBool DataType = "map[string]bool" // map -> map[string]bool
DataTypeMapStrBoolWithMarshal DataType = "map[string]bool_marshal" // map -> map[string]bool,json序列换之后的结果
DataTypeMapStrAny DataType = "map[string]any" // map -> map[string]any
DataTypeMapStrAnyWithMarshal DataType = "map[string]any_marshal" // map -> map[string]any, json序列化之后的结果
DataTypeMapStrStr DataType = "map[string]string" // map -> map[string]string
DataTypeMapStrStrWithMarshal DataType = "map[string]string_marshal" // map -> map[string]string, json序列化之后的结果
DataTypeMapAnyAny DataType = "map[any]any" // map -> map[any]any
DataTypeMapAnyAnyWithMarshal DataType = "map[any]any_marshal" // map -> map[any]any, json序列化之后的结果
DataTypeMapStrSlice DataType = "map[string][]any" // map -> map[string][]any
DataTypeMapStrSliceWithMarshal DataType = "map[string][]any_marshal" // map -> map[string][]any, json 序列化之后的结果
DataTypeAny DataType = "any" // 任意类型 -> any
DataTypeStringPtr DataType = "string_ptr" // *string, 字符串指针
DataTypeIntPtr DataType = "int_ptr" // *int64, int64指针
DataTypeUintPtr DataType = "uint_ptr" // *uint64, uint64指针
DataTypeFloatPtr DataType = "float_ptr" // *float64, float64指针
DataTypeBoolPtr DataType = "bool_ptr" // *bool, 字符串指针
2024-04-08 16:35:10 +08:00
)
2024-04-29 13:57:35 +08:00
const (
2024-04-29 16:02:51 +08:00
DataStatusNotFound = "NOT_FOUND"
DataStatusIsNil = "IS_NIL"
DataStatusIsZero = "IS_ZERO"
DataStatusIsEmpty = "IS_EMPTY"
DataStatusIsFalse = "IS_FALSE"
2024-04-29 13:57:35 +08:00
)
2024-04-30 21:51:09 +08:00
const (
DataSliceModelReal = "REAL"
DataSliceModelMarshal = "MARSHAL"
DataSliceModelWithSplitChar = "WITH_SPLIT_CHAR"
)
2024-06-23 11:12:47 +08:00
const (
DataMapModelReal = "REAL"
DataMapModelMarshal = "MARSHAL"
)
2024-06-23 13:51:43 +08:00
// DataTypeDesc 数据类型描述
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 13:22 2024/6/23
type DataTypeDesc struct {
2024-11-25 14:51:14 +08:00
Value DataType `json:"value"` // 具体数据类型
Description string `json:"description"` // 数据类型描述
2024-06-23 13:51:43 +08:00
}
var (
DataTypeList = []DataTypeDesc{
// 基础数据类型
getDataTypeDesc(DataTypeAny, "任意数据类型"),
getDataTypeDesc(DataTypeInt, "int类型 -> int64"),
getDataTypeDesc(DataTypeUint, "uint类型 -> uint64"),
getDataTypeDesc(DataTypeFloat, "float类型 -> float64"),
getDataTypeDesc(DataTypeBool, "bool类型"),
getDataTypeDesc(DataTypeString, "字符串类型"),
// map数据类型
getDataTypeDesc(DataTypeMapStrAny, "map[string]any"),
getDataTypeDesc(DataTypeMapStrAnyWithMarshal, "map[string]any json序列化之后的结果"),
getDataTypeDesc(DataTypeMapStrInt, "map[string]int64"),
getDataTypeDesc(DataTypeMapStrIntWithMarshal, "map[string]int64 json序列化之后的结果"),
getDataTypeDesc(DataTypeMapStrUint, "map[string]uint64"),
getDataTypeDesc(DataTypeMapStrUintWithMarshal, "map[string]uint64 json序列化之后的结果"),
getDataTypeDesc(DataTypeMapStrFloat, "map[string]float64"),
getDataTypeDesc(DataTypeMapStrFloatWithMarshal, "map[string]float64 json序列化之后的结果"),
getDataTypeDesc(DataTypeMapStrBool, "map[string]bool"),
getDataTypeDesc(DataTypeMapStrBoolWithMarshal, "map[string]bool json序列化之后的结果"),
getDataTypeDesc(DataTypeMapStrStr, "map[string]string"),
getDataTypeDesc(DataTypeMapStrStrWithMarshal, "map[string]string json序列化之后的结果"),
getDataTypeDesc(DataTypeMapAnyAny, "map[any]any"),
getDataTypeDesc(DataTypeMapAnyAnyWithMarshal, "map[any]any json序列化之后的结果"),
getDataTypeDesc(DataTypeMapStrSlice, "map[string][]any"),
getDataTypeDesc(DataTypeMapStrSliceWithMarshal, "map[string][]any json序列化之后的结果"),
// slice数据类型
getDataTypeDesc(DataTypeSliceAny, "[]any"),
getDataTypeDesc(DataTypeSliceString, "[]string"),
getDataTypeDesc(DataTypeSliceStringWithChar, "[]string 按照指定字符切割"),
getDataTypeDesc(DataTypeSliceStringWithMarshal, "[]string json序列化之后的结果"),
getDataTypeDesc(DataTypeSliceAnyWithMarshal, "[]any json序列化之后的结果"),
getDataTypeDesc(DataTypeSliceInt, "[]int"),
getDataTypeDesc(DataTypeSliceIntWithChar, "[]int 按照指定字符切割"),
getDataTypeDesc(DataTypeSliceIntWithMarshal, "[]int json序列化之后的结果"),
getDataTypeDesc(DataTypeSliceUint, "[]uint"),
getDataTypeDesc(DataTypeSliceUintWithChar, "[]uint 按照指定字符切割"),
getDataTypeDesc(DataTypeSliceUintWithMarshal, "[]uint json序列化之后的结果"),
getDataTypeDesc(DataTypeSliceFloat, "[]float"),
getDataTypeDesc(DataTypeSliceFloatWithChar, "[]float 按照指定字符切割"),
getDataTypeDesc(DataTypeSliceFloatWithMarshal, "[]float json序列化之后的结果"),
getDataTypeDesc(DataTypeSliceBool, "[]bool"),
getDataTypeDesc(DataTypeSliceBoolWithChar, "[]bool 按照指定字符切割"),
getDataTypeDesc(DataTypeSliceBoolWithMarshal, "[]bool json序列化之后的结果"),
getDataTypeDesc(DataTypeSliceSlice, "[][]any"),
getDataTypeDesc(DataTypeSliceSliceWithMarshal, "[][]any json序列化之后的结果"),
getDataTypeDesc(DataTypeSliceMapStringAny, "[][]map[string]any"),
getDataTypeDesc(DataTypeSliceMapStringAnyWithMarshal, "[][]map[string]any json序列化之后的结果"),
getDataTypeDesc(DataTypeSliceMapAnyAny, "[]map[any]any"),
getDataTypeDesc(DataTypeSliceMapAnyAnyWithMarshal, "[]map[any]any json序列化之后的结果"),
// 基础类型的指针类型
getDataTypeDesc(DataTypeStringPtr, "*string, 字符串指针"),
getDataTypeDesc(DataTypeUintPtr, "*int64, int64指针"),
getDataTypeDesc(DataTypeIntPtr, "*int64, *uint64, uint64指针"),
getDataTypeDesc(DataTypeFloatPtr, "*float64, float64指针"),
getDataTypeDesc(DataTypeBoolPtr, "*bool, 字符串指针"),
2024-06-23 13:51:43 +08:00
}
)
// getDataTypeDesc ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 13:24 2024/6/23
2024-11-25 14:51:14 +08:00
func getDataTypeDesc(value DataType, description string) DataTypeDesc {
2024-06-23 13:51:43 +08:00
return DataTypeDesc{
Value: value,
Description: description,
}
}
2025-01-22 17:53:00 +08:00
var (
// DataTypeBaseNumber 基础的int类型
2025-01-24 15:05:46 +08:00
DataTypeBaseNumber = []DataType{DataTypeInt, DataTypeUint, DataTypeFloat, DataTypeIntPtr, DataTypeUintPtr, DataTypeFloatPtr}
DataTypeBaseInt = []DataType{DataTypeInt, DataTypeIntPtr}
DataTypeBaseUint = []DataType{DataTypeUint, DataTypeUintPtr}
DataTypeBaseFloat = []DataType{DataTypeFloat, DataTypeFloatPtr}
DataTypeBaseString = []DataType{DataTypeString, DataTypeStringPtr}
DataTypeBaseBool = []DataType{DataTypeBool, DataTypeBoolPtr}
DataTypeSliceMarshal = []DataType{
DataTypeSliceAnyWithMarshal,
DataTypeSliceIntWithMarshal,
DataTypeSliceUintWithMarshal,
DataTypeSliceFloatWithMarshal,
DataTypeSliceBoolWithMarshal,
DataTypeSliceMapAnyAnyWithMarshal,
DataTypeSliceMapStringAnyWithMarshal,
DataTypeSliceAnyWithMarshal,
DataTypeSliceSliceWithMarshal,
}
DataTypeSliceSplit = []DataType{
DataTypeSliceIntWithChar,
DataTypeSliceUintWithChar,
DataTypeSliceFloatWithChar,
DataTypeSliceBoolWithChar,
DataTypeSliceStringWithChar,
}
DataTypeSlice = []DataType{
DataTypeSliceString,
DataTypeSliceAny,
DataTypeSliceBool,
DataTypeSliceMapStringAny,
DataTypeSliceInt,
DataTypeSliceUint,
DataTypeSliceFloat,
DataTypeSliceMapAnyAny,
DataTypeSliceSlice,
}
DataTypeMap = []DataType{
DataTypeMapStrAny,
DataTypeMapAnyAny,
DataTypeMapStrBool,
DataTypeMapStrInt,
DataTypeMapStrFloat,
DataTypeMapStrUint,
DataTypeMapStrSlice,
DataTypeMapStrStr,
}
DataTypeMapMarshal = []DataType{
DataTypeMapStrAnyWithMarshal,
DataTypeMapAnyAnyWithMarshal,
DataTypeMapStrBoolWithMarshal,
DataTypeMapStrIntWithMarshal,
DataTypeMapStrFloatWithMarshal,
DataTypeMapStrUintWithMarshal,
DataTypeMapStrSliceWithMarshal,
DataTypeMapStrStrWithMarshal,
}
2025-01-22 17:53:00 +08:00
)
func getMergeDataTypeList(dataTypeList ...[]DataType) []DataType {
res := []DataType{}
for _, dataTypeItemList := range dataTypeList {
res = append(res, dataTypeItemList...)
}
return res
}