diff --git a/reflect.go b/reflect.go index 3bae95c..156df09 100644 --- a/reflect.go +++ b/reflect.go @@ -71,11 +71,11 @@ func (rt *ReflectType) Do(dataFlag string, data interface{}) *StructInfo { field := &StructField{ Idx: idx, Name: reflectType.Field(idx).Name, - Type: reflectType.Field(idx).Type.Kind(), JsonTag: reflectType.Field(idx).Tag.Get(JsonTag), EventTag: reflectType.Field(idx).Tag.Get(OutEventTag), MappingRuleList: make([]MappingRuleItem, 0), } + rt.fillFieldType(field, reflectType.Field(idx).Type.Kind()) rt.fillMappingRule(field, reflectType.Field(idx).Tag.Get(MappingTag)) res.StructFieldList = append(res.StructFieldList, field) } @@ -83,6 +83,28 @@ func (rt *ReflectType) Do(dataFlag string, data interface{}) *StructInfo { return res } +// fillFieldType 填充字段类型 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:46 2023/2/1 +func (rt *ReflectType) fillFieldType(field *StructField, dataType reflect.Kind) { + switch dataType { + case reflect.Float32: + fallthrough + case reflect.Float64: + field.Type = reflect.Float64 + case reflect.String: + field.Type = reflect.String + default: + if strings.Contains(dataType.String(), "int") { + field.Type = reflect.Int64 + } else { + field.Type = reflect.Interface + } + } +} + // fillTagInfo 填充标签信息 // // Author : go_developer@163.com<白茶清欢>