This commit is contained in:
John Guo
2025-03-02 22:46:27 +08:00
parent b52ba15e43
commit d7a246c4c7
5 changed files with 9 additions and 11 deletions

View File

@ -33,9 +33,6 @@ type Converter interface {
Float32(any any) (float32, error)
Float64(any any) (float64, error)
doMapConvert(
value any, recursive recursiveType, mustMapReturn bool, option ...MapOption,
) map[string]any
MapToMap(params any, pointer any, mapping ...map[string]string) (err error)
MapToMaps(params any, pointer any, paramKeyToAttrMap ...map[string]string) (err error)
Rune(any any) (rune, error)

View File

@ -310,10 +310,10 @@ func (c *impConverter) doConvert(in doConvertInput) (convertedValue any, err err
return &v, nil
case "map[string]string":
return MapStrStr(in.FromValue), nil
return c.MapStrStr(in.FromValue, MapOption{})
case "map[string]interface {}":
return Map(in.FromValue, MapOption{}), nil
return c.Map(in.FromValue, MapOption{})
case "[]map[string]interface {}":
return c.SliceMap(in.FromValue, SliceOption{}, MapOption{})

View File

@ -103,13 +103,13 @@ func (c *impConverter) MapToMaps(params any, pointer any, paramKeyToAttrMap ...m
var item reflect.Value
if pointerElemType.Kind() == reflect.Ptr {
item = reflect.New(pointerElemType.Elem())
if err = MapToMap(paramsRv.Index(i).Interface(), item, paramKeyToAttrMap...); err != nil {
if err = c.MapToMap(paramsRv.Index(i).Interface(), item, paramKeyToAttrMap...); err != nil {
return err
}
pointerSlice.Index(i).Set(item)
} else {
item = reflect.New(pointerElemType)
if err = MapToMap(paramsRv.Index(i).Interface(), item, paramKeyToAttrMap...); err != nil {
if err = c.MapToMap(paramsRv.Index(i).Interface(), item, paramKeyToAttrMap...); err != nil {
return err
}
pointerSlice.Index(i).Set(item.Elem())

View File

@ -15,6 +15,7 @@ import (
"github.com/gogf/gf/v2/util/gconv/internal/localinterface"
)
// SliceOption is the option for Slice type converting.
type SliceOption struct {
// BreakOnError specifies whether to break converting the next element
// if one element conversion fails in slice.

View File

@ -48,10 +48,10 @@ func (c *impConverter) SliceMap(value any, sliceOption SliceOption, mapOption Ma
}
list := make([]map[string]any, len(array))
for k, v := range array {
m := Map(v, mapOption)
//if err != nil {
// return nil, err
//}
m, err := c.Map(v, mapOption)
if err != nil && sliceOption.BreakOnError {
return nil, err
}
list[k] = m
}
return list, nil