func GetMapValue()

in pkg/client/mapper.go [53:73]


func GetMapValue(sourceMap map[string]any, keys []string) (any, error) {
	if len(keys) > 0 && keys[0] == constant.DefaultBodyAll {
		return sourceMap, nil
	}
	_, ok := sourceMap[keys[0]]
	if !ok {
		return nil, errors.Errorf("%s does not exist in request body", keys[0])
	}
	rvalue := reflect.ValueOf(sourceMap[keys[0]])
	if ok && len(keys) == 1 {
		return rvalue.Interface(), nil
	}
	if rvalue.Type().Kind() != reflect.Map && len(keys) == 1 {
		return rvalue.Interface(), nil
	}
	deeperStruct, ok := sourceMap[keys[0]].(map[string]any)
	if !ok {
		return nil, errors.Errorf("%s is not a map structure. It contains %v", keys[0], sourceMap[keys[0]])
	}
	return GetMapValue(deeperStruct, keys[1:])
}