title: Segmentation violation with golang channels
body: <p>The below code opens 10,000 go routines, which make HTTP calls, get the response, close the response, and write to a channel with an ID. </p>
  
  <p>In the second for loop, it prints out from that buffered channel the ID of the previous go routine.</p>
  
  <p>This causes a segmentation violation, and I can't figure out why.</p>
  
  <p>Panic:</p>
  
  <pre><code>panic: runtime error: invalid memory address or nil pointer dereference
  [signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x2293]
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "net/http"
  )
  
  func main() {
      requests := 10000
      ch := make(chan string, requests)
      for i := 1; i &lt;= requests; i++ {
          go func(iter int) {
              fmt.Println(iter)
              resp, _ := http.Get("http://localhost:8080/api/project")
              resp.Body.Close()
              ch &lt;- fmt.Sprint("%i", iter)
          }(i)
      }
      for i := 1; i &lt;= requests; i++ {
          fmt.Println(&lt;-ch)
      }
  }
  </code></pre>