title: Golang: Read ints from stdin until EOF while reporting format errors
body: <pre><code>nums := make([]int, 0)
  {
      var d int
      for {
          _, err := fmt.Scan(&amp;d)
          if err != nil {
              break
          }
  
          nums = append(nums, d)
      }
  }
  </code></pre>
  
  <p>This works to read in ints from stdin. But if stdin looks like <code>1 2 3 f4 5</code>, <code>nums</code> will end up being <code>[1 2 3]</code> without reporting any error.</p>
  
  <p>What's the best way of handling this? (Ie, I want EOF from <code>fmt.Scan</code> to silently exit the loop, but all other errors should be reported).</p>
  
  <p><strong>edit</strong>: <code>io.EOF</code> was all I needed -- I hadn't found that documented at <a href="http://golang.org/pkg/fmt/">http://golang.org/pkg/fmt/</a></p>
  
  <pre><code>nums := make([]int, 0)
  {
      var d int
      for {
          _, err := fmt.Scan(&amp;d)
          if err != nil {
              if err != io.EOF {
                  log.Fatal(err)
              }
              break
          }
  
          nums = append(nums, d)
      }
  }
  </code></pre>