字段反射增加是否指针的判断
This commit is contained in:
parent
a30861a898
commit
b22753fbbb
@ -76,6 +76,7 @@ type StructField struct {
|
||||
Idx int // 字段在结构体的索引
|
||||
Name string // 字段名
|
||||
Type reflect.Kind // 字段类型
|
||||
IsPtr bool // 是否为指针
|
||||
JsonTag string // json标签
|
||||
EventTag string // 事件标签
|
||||
MappingRuleList []MappingRuleItem // 规则列表
|
||||
|
13
reflect.go
13
reflect.go
@ -81,7 +81,7 @@ func (rt *ReflectType) Do(dataFlag string, data interface{}) *StructInfo {
|
||||
EventTag: reflectType.Field(idx).Tag.Get(OutEventTag),
|
||||
MappingRuleList: make([]MappingRuleItem, 0),
|
||||
}
|
||||
rt.fillFieldType(field, reflectType.Field(idx).Type.Kind())
|
||||
rt.fillFieldType(field, reflectType.Field(idx).Type)
|
||||
rt.fillMappingRule(field, reflectType.Field(idx).Tag.Get(MappingTag))
|
||||
res.StructFieldList = append(res.StructFieldList, field)
|
||||
}
|
||||
@ -94,14 +94,20 @@ func (rt *ReflectType) Do(dataFlag string, data interface{}) *StructInfo {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 20:46 2023/2/1
|
||||
func (rt *ReflectType) fillFieldType(field *StructField, dataType reflect.Kind) {
|
||||
switch dataType {
|
||||
func (rt *ReflectType) fillFieldType(field *StructField, dataType reflect.Type) {
|
||||
switch dataType.Kind() {
|
||||
case reflect.Float32:
|
||||
fallthrough
|
||||
case reflect.Float64:
|
||||
field.Type = reflect.Float64
|
||||
case reflect.String:
|
||||
field.Type = reflect.String
|
||||
case reflect.Struct:
|
||||
field.Type = reflect.Struct
|
||||
case reflect.Ptr:
|
||||
field.IsPtr = true
|
||||
// 指针再次判断基础类型
|
||||
field.Type = dataType.Elem().Kind()
|
||||
default:
|
||||
if strings.Contains(dataType.String(), "int") {
|
||||
field.Type = reflect.Int64
|
||||
@ -243,6 +249,7 @@ func (rv *ReflectValue) Do(dataFlag string, data interface{}, preSendHandler abs
|
||||
// 不是零值, 无需处理
|
||||
continue
|
||||
}
|
||||
// 是零值, 填充默认值
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user