MCPcopy Create free account
hub / github.com/devfeel/mapper / MapperMapSlice

Method MapperMapSlice

mapper_object.go:275–304  ·  view source on GitHub ↗

MapperMapSlice mapper from map[string]map[string]interface{} to a slice of any type's ptr toSlice must be a slice of any type. Deprecated: will remove on v1.0, please use MapToSlice instead

(fromMaps map[string]map[string]interface{}, toSlice interface{})

Source from the content-addressed store, hash-verified

273// toSlice must be a slice of any type.
274// Deprecated: will remove on v1.0, please use MapToSlice instead
275func (dm *mapperObject) MapperMapSlice(fromMaps map[string]map[string]interface{}, toSlice interface{}) error {
276 var err error
277 toValue := reflect.ValueOf(toSlice)
278 if toValue.Kind() != reflect.Ptr {
279 return errors.New("toSlice must be a pointer to a slice")
280 }
281 if toValue.IsNil() {
282 return errors.New("toSlice must not be a nil pointer")
283 }
284
285 toElemType := reflect.TypeOf(toSlice).Elem().Elem()
286 realType := toElemType.Kind()
287 direct := reflect.Indirect(toValue)
288 // 3 elem parse: 1.[]*type 2.*type 3.type
289 if realType == reflect.Ptr {
290 toElemType = toElemType.Elem()
291 }
292 for _, v := range fromMaps {
293 elem := reflect.New(toElemType)
294 err = dm.MapperMap(v, elem.Interface())
295 if err == nil {
296 if realType == reflect.Ptr {
297 direct.Set(reflect.Append(direct, elem))
298 } else {
299 direct.Set(reflect.Append(direct, elem.Elem()))
300 }
301 }
302 }
303 return err
304}
305
306// MapperSlice mapper from slice of struct to a slice of any type
307// fromSlice and toSlice must be a slice of any type.

Callers

nothing calls this directly

Calls 2

MapperMapMethod · 0.95
SetMethod · 0.80

Tested by

no test coverage detected