Getting response from function without return - Golang
<p>I have a service function in Golang where running an endless for loop. I wanted to get data from this function without return. What is the best solution, a channel, or io.Writer? The function and where I call it in a different package, because the funcion in <code>package something</code> while where I call it is the main. There is an example with channels: </p>

<pre><code>func Check(dst string, w chan string) bool {    
  for {
    w &lt;- data
  }
  return false
}
</code></pre>

<p>On the otherside where I call this function:</p>

<pre><code>var wg sync.WaitGroup
func main() {
    messages := make(chan string, 10)

    wg.Add(3)
    go checking("10.1.1.1", messages)
    msg := &lt;-messages
    fmt.Println(msg)
    wg.Wait()
}

func checking(ip string, msg chan string) {
    defer wg.Done()
    w := worker.ContainerAliveIndicator{}
    w.Check(ip, msg)
}
</code></pre>

<p>In this case I only get the first message what the function take to the channel. </p>