From 1e0c756917b5b3540031b0c9118f64ae0d3f7e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 2 Feb 2023 10:52:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=B1=BB=E5=9E=8B=E5=A1=AB?= =?UTF-8?q?=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reflect.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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<白茶清欢>