mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
up
This commit is contained in:
@ -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)
|
||||
|
||||
@ -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{})
|
||||
|
||||
@ -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())
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user