engine: Allow more send/recv cases
This allows the other part of this. This still needs to be improved, but it unblocks some use-cases.
This commit is contained in:
@@ -93,12 +93,18 @@ func (obj *Engine) SendRecv(res engine.RecvableRes) (map[string]bool, error) {
|
|||||||
value2 := obj2.FieldByName(key2)
|
value2 := obj2.FieldByName(key2)
|
||||||
kind2 := value2.Kind()
|
kind2 := value2.Kind()
|
||||||
|
|
||||||
|
dest := value2 // save the o.g. because we need the real dest!
|
||||||
|
|
||||||
// For situations where we send a variant to the resource!
|
// For situations where we send a variant to the resource!
|
||||||
// TODO: should this be a for loop to un-nest multiple times?
|
// TODO: should this be a for loop to un-nest multiple times?
|
||||||
if kind1 == reflect.Interface {
|
if kind1 == reflect.Interface {
|
||||||
value1 = value1.Elem() // un-nest one interface
|
value1 = value1.Elem() // un-nest one interface
|
||||||
kind1 = value1.Kind()
|
kind1 = value1.Kind()
|
||||||
}
|
}
|
||||||
|
if kind2 == reflect.Interface {
|
||||||
|
value2 = value2.Elem() // un-nest one interface
|
||||||
|
kind2 = value2.Kind()
|
||||||
|
}
|
||||||
|
|
||||||
if obj.Debug {
|
if obj.Debug {
|
||||||
obj.Logf("Send(%s) has %v: %v", type1, kind1, value1)
|
obj.Logf("Send(%s) has %v: %v", type1, kind1, value1)
|
||||||
@@ -121,7 +127,7 @@ func (obj *Engine) SendRecv(res engine.RecvableRes) (map[string]bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we can't set, then well this is pointless!
|
// if we can't set, then well this is pointless!
|
||||||
if !value2.CanSet() {
|
if !dest.CanSet() {
|
||||||
e := fmt.Errorf("can't set %s.%s", res, k)
|
e := fmt.Errorf("can't set %s.%s", res, k)
|
||||||
err = errwrap.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
@@ -141,7 +147,7 @@ func (obj *Engine) SendRecv(res engine.RecvableRes) (map[string]bool, error) {
|
|||||||
|
|
||||||
// TODO: can we catch the panics here in case they happen?
|
// TODO: can we catch the panics here in case they happen?
|
||||||
|
|
||||||
value2.Set(value1) // do it for all types that match
|
dest.Set(value1) // do it for all types that match
|
||||||
updated[k] = true // we updated this key!
|
updated[k] = true // we updated this key!
|
||||||
v.Changed = true // tag this key as updated!
|
v.Changed = true // tag this key as updated!
|
||||||
obj.Logf("SendRecv: %s.%s -> %s.%s", v.Res, v.Key, res, k)
|
obj.Logf("SendRecv: %s.%s -> %s.%s", v.Res, v.Key, res, k)
|
||||||
|
|||||||
@@ -197,6 +197,11 @@ func StructFieldCompat(st1 interface{}, key1 string, st2 interface{}, key2 strin
|
|||||||
// TODO: Can we do more checks instead of only returning early?
|
// TODO: Can we do more checks instead of only returning early?
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
// If we're sending _to_ an interface...
|
||||||
|
//if kind2 == reflect.Interface {
|
||||||
|
// // TODO: Can we do more checks instead of only returning early?
|
||||||
|
// return nil
|
||||||
|
//}
|
||||||
|
|
||||||
if kind1 != kind2 {
|
if kind1 != kind2 {
|
||||||
return fmt.Errorf("field kind mismatch between %s and %s", kind1, kind2)
|
return fmt.Errorf("field kind mismatch between %s and %s", kind1, kind2)
|
||||||
|
|||||||
Reference in New Issue
Block a user