增加struct => wrapper.Map的能力
This commit is contained in:
parent
0a9175daa8
commit
91eca55f87
7
map.go
7
map.go
@ -12,6 +12,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"git.zhangdeman.cn/zhangdeman/easymap"
|
||||
"git.zhangdeman.cn/zhangdeman/serialize"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@ -37,7 +38,11 @@ func EasyMapWithError(mapData interface{}) (Map, error) {
|
||||
m := easymap.NewNormal(true)
|
||||
reflectType := reflect.TypeOf(mapData)
|
||||
if reflectType.Kind() != reflect.Map {
|
||||
return m, errors.New("input data type is " + reflectType.String() + ", not map")
|
||||
mapFormatData := make(map[string]interface{})
|
||||
if err := serialize.JSON.UnmarshalWithNumber(serialize.JSON.MarshalForByte(mapData), &mapFormatData); nil != err {
|
||||
return m, errors.New("input data type is " + reflectType.String() + ", can not convert to map")
|
||||
}
|
||||
mapData = mapFormatData
|
||||
}
|
||||
|
||||
reflectValue := reflect.ValueOf(mapData).MapRange()
|
||||
|
Loading…
Reference in New Issue
Block a user