title: Goroutines and Channels with Multiple Types
body: <p>I'm relatively new to Go and trying to figure out the best way to concurrently pull information from a <code>REST API</code>. The intent is to make multiple concurrent calls to an <code>API</code>, with each call returning a different type of data.</p>
  
  <p>I currently have:</p>
  
  <pre><code>s := NewClient()
  c1 := make(chan map[string]Service)
  c2 := make(chan map[string]ServicePlan)
  c3 := make(chan map[string]ServiceInstance)
  c4 := make(chan map[string]ServiceBinding)
  c5 := make(chan map[string]Organization)
  c6 := make(chan map[string]Space)
  
  go func() {
      c1 &lt;- GetServices(s)
  }()
  
  go func() {
      c2 &lt;- GetServicePlans(s)
  }()
  
  go func() {
      c3 &lt;- GetServiceInstances(s)
  }()
  
  go func() {
      c4 &lt;- GetServiceBindings(s)
  }()
  
  go func() {
      c5 &lt;- GetOrganizations(s)
  }()
  
  go func() {
      c6 &lt;- GetSpaces(s)
  }()
  
  services := &lt;- c1
  servicePlans := &lt;- c2
  serviceInstances := &lt;- c3
  serviceBindings := &lt;- c4
  orgs := &lt;- c5
  spaces := &lt;- c6
  // stitch all the data together later
  </code></pre>
  
  <p>but I was wondering if there was a better way to write this.</p>
  
  <p>EDIT: It's still ugly, but reduced the number of channels to one:</p>
  
  <pre><code>c := make(chan interface{})
  
  var (
      services     map[string]Service
      servicePlans     map[string]ServicePlan
      serviceInstances map[string]ServiceInstance
      serviceBindings  map[string]ServiceBinding
      orgs         map[string]Organization
      spaces       map[string]Space
  )
  
  go func() {
      c &lt;- GetServices(s)
  }()
  
  go func() {
      c &lt;- GetServicePlans(s)
  }()
  
  go func() {
      c &lt;- GetServiceInstances(s)
  }()
  
  go func() {
      c &lt;- GetServiceBindings(s)
  }()
  
  go func() {
      c &lt;- GetOrganizations(s)
  }()
  
  go func() {
      c &lt;- GetSpaces(s)
  }()
  
  for i := 0; i &lt; 6; i++ {
      v := &lt;-c
      switch v := v.(type) {
      case map[string]Service:
          services = v
      case map[string]ServicePlan:
          servicePlans = v
      case map[string]ServiceInstance:
          serviceInstances = v
      case map[string]ServiceBinding:
          serviceBindings = v
      case map[string]Organization:
          orgs = v
      case map[string]Space:
          spaces = v
      }
  }
  </code></pre>
  
  <p>I would still really like a way to do this so I don't have to hard-code that the loop needs to run 6 times. I actually tried make a list of functions to run and doing it that way to remove the repetitive <code>go func</code> calls, but since all the functions have different return types, I got all type mismatch errors, and you can't fake it by using <code>func(api) interface{}</code> either as that just creates a runtime panic.</p>