mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
integration test for *cgr_rpc
This commit is contained in:
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user