Dereference pointers when publishing (#7905)
This commit is contained in:
parent
b97850afd0
commit
229a2d2b34
1 changed files with 9 additions and 0 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package util
|
||||
|
||||
import "reflect"
|
||||
|
||||
// TeeAttacher allows to attach a listener to a tee
|
||||
type TeeAttacher interface {
|
||||
Attach() <-chan Param
|
||||
|
|
@ -28,6 +30,13 @@ func (t *Tee) add(out chan<- Param) {
|
|||
func (t *Tee) Run(in <-chan Param) {
|
||||
for msg := range in {
|
||||
for _, recv := range t.recv {
|
||||
// dereference pointers (https://github.com/evcc-io/evcc/issues/7895)
|
||||
if val := reflect.ValueOf(msg.Val); val.Kind() == reflect.Ptr {
|
||||
if ptr := reflect.Indirect(val); ptr.IsValid() {
|
||||
msg.Val = ptr.Addr().Elem().Interface()
|
||||
}
|
||||
}
|
||||
|
||||
recv <- msg
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue