title: go - reading binary file with struct
body: <p>I'm trying to reading binary files with golang, but have a question.</p>
  
  <p>If I read it this way, all will be fine</p>
  
  <pre><code>package main
  
  import (
      "encoding/binary"
      "fmt"
      "os"
  )
  
  type Header struct {
      str1 int32
      str2 [255]byte
      str3 float64
  }
  
  func main() {
  
      path := "test.BIN"
  
      file, _ := os.Open(path)
  
      defer file.Close()
  
      thing := Header{}
      binary.Read(file, binary.LittleEndian, &amp;thing.str1)
      binary.Read(file, binary.LittleEndian, &amp;thing.str2)
      binary.Read(file, binary.LittleEndian, &amp;thing.str3)
  
      fmt.Println(thing)
  }
  </code></pre>
  
  <p>But if I optimize the .Read-Section to</p>
  
  <pre><code>binary.Read(file, binary.LittleEndian, &amp;thing)
  //binary.Read(file, binary.LittleEndian, &amp;thing.str1)
  //binary.Read(file, binary.LittleEndian, &amp;thing.str2)
  //binary.Read(file, binary.LittleEndian, &amp;thing.str3)
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>panic: reflect: reflect.Value.SetInt using value obtained using unexported field
  </code></pre>
  
  <p>Could anybody say me why?</p>
  
  <p>All examples are useing the "optimized-way"</p>
  
  <p>Thanks :)</p>