@@ -11,13 +11,12 @@ import (
1111
1212 "github.com/gogf/gf/v2/errors/gcode"
1313 "github.com/gogf/gf/v2/errors/gerror"
14- "github.com/gogf/gf/v2/internal/json"
1514)
1615
1716// MapToMaps converts any slice type variable `params` to another map slice type variable `pointer`.
1817// See doMapToMaps.
1918func MapToMaps (params interface {}, pointer interface {}, mapping ... map [string ]string ) error {
20- return doMapToMaps (params , pointer , mapping ... )
19+ return Scan (params , pointer , mapping ... )
2120}
2221
2322// doMapToMaps converts any map type variable `params` to another map slice variable `pointer`.
@@ -29,29 +28,6 @@ func MapToMaps(params interface{}, pointer interface{}, mapping ...map[string]st
2928// The optional parameter `mapping` is used for struct attribute to map key mapping, which makes
3029// sense only if the item of `params` is type struct.
3130func doMapToMaps (params interface {}, pointer interface {}, paramKeyToAttrMap ... map [string ]string ) (err error ) {
32- // If given `params` is JSON, it then uses json.Unmarshal doing the converting.
33- switch r := params .(type ) {
34- case []byte :
35- if json .Valid (r ) {
36- if rv , ok := pointer .(reflect.Value ); ok {
37- if rv .Kind () == reflect .Ptr {
38- return json .UnmarshalUseNumber (r , rv .Interface ())
39- }
40- } else {
41- return json .UnmarshalUseNumber (r , pointer )
42- }
43- }
44- case string :
45- if paramsBytes := []byte (r ); json .Valid (paramsBytes ) {
46- if rv , ok := pointer .(reflect.Value ); ok {
47- if rv .Kind () == reflect .Ptr {
48- return json .UnmarshalUseNumber (paramsBytes , rv .Interface ())
49- }
50- } else {
51- return json .UnmarshalUseNumber (paramsBytes , pointer )
52- }
53- }
54- }
5531 // Params and its element type check.
5632 var (
5733 paramsRv reflect.Value
@@ -68,7 +44,10 @@ func doMapToMaps(params interface{}, pointer interface{}, paramKeyToAttrMap ...m
6844 paramsKind = paramsRv .Kind ()
6945 }
7046 if paramsKind != reflect .Array && paramsKind != reflect .Slice {
71- return gerror .NewCode (gcode .CodeInvalidParameter , "params should be type of slice, eg: []map/[]*map/[]struct/[]*struct" )
47+ return gerror .NewCode (
48+ gcode .CodeInvalidParameter ,
49+ "params should be type of slice, example: []map/[]*map/[]struct/[]*struct" ,
50+ )
7251 }
7352 var (
7453 paramsElem = paramsRv .Type ().Elem ()
@@ -78,8 +57,14 @@ func doMapToMaps(params interface{}, pointer interface{}, paramKeyToAttrMap ...m
7857 paramsElem = paramsElem .Elem ()
7958 paramsElemKind = paramsElem .Kind ()
8059 }
81- if paramsElemKind != reflect .Map && paramsElemKind != reflect .Struct && paramsElemKind != reflect .Interface {
82- return gerror .NewCodef (gcode .CodeInvalidParameter , "params element should be type of map/*map/struct/*struct, but got: %s" , paramsElemKind )
60+ if paramsElemKind != reflect .Map &&
61+ paramsElemKind != reflect .Struct &&
62+ paramsElemKind != reflect .Interface {
63+ return gerror .NewCodef (
64+ gcode .CodeInvalidParameter ,
65+ "params element should be type of map/*map/struct/*struct, but got: %s" ,
66+ paramsElemKind ,
67+ )
8368 }
8469 // Empty slice, no need continue.
8570 if paramsRv .Len () == 0 {
0 commit comments