title: Golang, is there a better way read a file of integers into an array?
body: <p>I need to read a file of integers into an array.  I have it working with this:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "io"
      "os"
  )
  
  func readFile(filePath string) (numbers []int) {
      fd, err := os.Open(filePath)
      if err != nil {
          panic(fmt.Sprintf("open %s: %v", filePath, err))
      }
      var line int
      for {
  
          _, err := fmt.Fscanf(fd, "%d\n", &amp;line)
  
          if err != nil {
              fmt.Println(err)
              if err == io.EOF {
                  return
              }
              panic(fmt.Sprintf("Scan Failed %s: %v", filePath, err))
  
          }
          numbers = append(numbers, line)
      }
      return
  }
  
  func main() {
      numbers := readFile("numbers.txt")
      fmt.Println(len(numbers))
  }
  </code></pre>
  
  <p>The file numbers.txt is just:</p>
  
  <pre><code>1
  2
  3
  ...
  </code></pre>
  
  <p><code>ReadFile()</code> seems too long (maybe because of the error handing).</p>
  
  <p>Is there a shorter / more Go idiomatic way to load a file?</p>