feature/upgrade_dynamic_struct #9
@ -183,9 +183,9 @@ func (ds *DynamicStruct) AddStructField(field reflect.StructField, fieldValue an
|
|||||||
if field.Tag == "" {
|
if field.Tag == "" {
|
||||||
field.Tag = reflect.StructTag(fmt.Sprintf(`json:"%v"`, field.Name))
|
field.Tag = reflect.StructTag(fmt.Sprintf(`json:"%v"`, field.Name))
|
||||||
}
|
}
|
||||||
|
ds.SetMapData(field.Name, fieldValue)
|
||||||
field.Name = String(field.Name).SnakeCaseToCamel() // 转成大驼峰, 保证对外可访问
|
field.Name = String(field.Name).SnakeCaseToCamel() // 转成大驼峰, 保证对外可访问
|
||||||
ds.structFieldList = append(ds.structFieldList, field)
|
ds.structFieldList = append(ds.structFieldList, field)
|
||||||
ds.SetMapData(field.Name, fieldValue)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStructType 获取结构体的类型
|
// GetStructType 获取结构体的类型
|
||||||
@ -248,3 +248,8 @@ func (ds *DynamicStruct) Clear() {
|
|||||||
func (ds *DynamicStruct) MarshalJSON() ([]byte, error) {
|
func (ds *DynamicStruct) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(ds.mapData)
|
return json.Marshal(ds.mapData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MapData map数据
|
||||||
|
func (ds *DynamicStruct) MapData() (map[string]any) {
|
||||||
|
return ds.mapData
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user