integration test for *cgr_rpc

This commit is contained in:
Radu Ioan Fericean
2016-04-20 00:39:14 +03:00
parent c174605ab8
commit da1a9b344c
9 changed files with 82 additions and 14 deletions

View File

@@ -194,6 +194,27 @@ func FromMapStringInterface(m map[string]interface{}, in interface{}) error {
return nil
}
func FromMapStringInterfaceValue(m map[string]interface{}, v reflect.Value) (interface{}, error) {
if v.Kind() == reflect.Ptr {
v = v.Elem()
}
for fieldName, fieldValue := range m {
field := v.FieldByName(fieldName)
if field.IsValid() {
if !field.IsValid() || !field.CanSet() {
continue
}
structFieldType := field.Type()
val := reflect.ValueOf(fieldValue)
if structFieldType != val.Type() {
return nil, errors.New("Provided value type didn't match obj field type")
}
field.Set(val)
}
}
return v.Interface(), nil
}
// Update struct with map fields, returns not matching map keys, s is a struct to be updated
func UpdateStructWithStrMap(s interface{}, m map[string]string) []string {
notMatched := []string{}