How to get chan value from an interface and use it in reflect.Select(...)
<p>I took an example of reflect.Select from:
 <strong><a href="https://www.socketloop.com/references/golang-reflect-select-and-selectcase-function-example" rel="nofollow">https://www.socketloop.com/references/golang-reflect-select-and-selectcase-function-example</a></strong></p>

<p>It works as far as it goes.  But it was creating the reflect.Value() from a simple
"chan" := make(chan int) setup.  </p>

<p>But I wanted to use a channel from a structure passed as an interface{}.</p>

<p>So I modified the program to create a struct and pass it to the processing as
an interface parameter.</p>

<p>When run I get:  <strong>panic: reflect: call of reflect.Value.Elem on struct Valuepanic: reflect: call of reflect.Value.Elem on struct Value</strong></p>

<p>This is strange because I the exact code another program that works!! </p>

<pre><code>func inspect(f interface{}) map[string]string {

    m := make(map[string]string)
    val := reflect.ValueOf(f).Elem()

    for i := 0; i &lt; val.NumField(); i++ {
        valueField := val.Field(i)
        typeField := val.Type().Field(i)
        f := valueField.Interface()

        val := reflect.ValueOf(f)
        m[typeField.Name] = val.String()
    }

    return m
}
</code></pre>

<p>Can any
body tell me where I am going wrong trying to use the interface code
in replace of the simple variable version.</p>

<p>The program is below with comments showing changes:</p>

<pre><code>package main

// Original Example from:
// https://www.socketloop.com/references/golang-reflect-select-and-selectcase-function-example
//
import (
    "fmt"
    "reflect"
)

func main() {

    // following replaces  " var sendCh := make(chan int) "
    type Foo struct {
        Ch chan int
    }
    sendCh := Foo{make(chan int)}
    // End of replacement code

    var increaseInt = func(c chan int) {
        for i := 0; i &lt; 8; i++ {
            c &lt;- i
        }
        close(c)
    }

    go increaseInt(sendCh.Ch)

    // This routine call replaces the code incorporated in "runJob"
    // It was done so I could call through an empty interface{}
    runJob(sendCh)
    // End replaement code--
}

func runJob(f interface{}) {
    var selectCase = make([]reflect.SelectCase, 1)

    // This code replaces just using the orginal "sendCh" value
    // I am trying here to construct "sendCh" from the interface value
    val := reflect.ValueOf(f).Elem()
    valueField := val.Field(0)
    sendCh := valueField.Interface()
    // End of replacement code

    selectCase[0].Dir = reflect.SelectRecv
    selectCase[0].Chan = reflect.ValueOf(sendCh)

    counter := 0
    for counter &lt; 1 {
        chosen, recv, recvOk := reflect.Select(selectCase) // &lt;--- here
        if recvOk {
            fmt.Println(chosen, recv.Int(), recvOk)

        } else {
            fmt.Println("Exit Condition Detected:  ", chosen, recv.Int(), recvOk)
            counter++
        }
    }
}
</code></pre>