title: Iterate through the fields of a struct in Go
body: <p>Basically, the only way (that I know of) to iterate through the values of the fields of a <code>struct</code> is like this:</p>
  
  <pre><code>type Example struct {
      a_number uint32
      a_string string
  }
  
  //...
  
  r := &amp;Example{(2 &lt;&lt; 31) - 1, "...."}:
  for _, d:= range []interface{}{ r.a_number, r.a_string, } {
    //do something with the d
  }
  </code></pre>
  
  <p>I was wondering, if there's a better and more versatile way of achieving <code>[]interface{}{ r.a_number, r.a_string, }</code>, so I don't need to list each parameter individually, or alternatively, is there a better way to loop through a struct?</p>
  
  <p>I tried to look through the <a href="http://golang.org/pkg/reflect/" rel="noreferrer"><code>reflect</code></a> package, but I hit a wall, because I'm not sure what to do once I retrieve <code>reflect.ValueOf(*r).Field(0)</code>.</p>
  
  <p>Thanks!</p>