feature/upgrade_dynamic_struct #9

Merged
zhangdeman merged 9 commits from feature/upgrade_dynamic_struct into master 2025-03-21 18:27:12 +08:00
Showing only changes of commit 2c73b9c034 - Show all commits

View File

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