title: How do I STORE different structs in a slice or a struct in Go (Not embedding)
body: <p>I am new to Golang, after I took a tour of <a href="https://tour.golang.org/welcome/1" rel="nofollow">A Tour of Go</a>, I'm trying to make my own thing.</p>
  
  <h2>What I want</h2>
  
  <p>I want to put different types of the structs into a single slice (or struct?),</p>
  
  <p>so I can use a <code>for</code> loop to <strong>pass each struct to a function</strong>.</p>
  
  <h2>For example</h2>
  
  <p>In PHP I can store my classes in an array and pass each of them to <code>foobar()</code> like this:</p>
  
  <pre><code>$classes = [$A, $B, $C, $D];  // $A, $B, $C, $D are classes (called `struct` in Golang).
  
  foreach ($classes as $class)
      foobar($class);
  </code></pre>
  
  <h2>What I tried</h2>
  
  <p>I tried to do the same in Golang, and I hope it looks like this:</p>
  
  <pre><code>A{B{}, C{}, D{}}
  </code></pre>
  
  <p>Since I failed on using <code>slice</code>, I decided to use <code>struct</code> to hold my <code>structs</code>:</p>
  
  <pre><code>type A struct {
      B
      C
      D
  }
  
  type B struct {
      Date string
  }
  
  type C struct {
      Date string
  }
  
  type D struct {
      Date string
  }
  
  func main() {   
      // Using reflect to loop the A struct: 
      // http://stackoverflow.com/questions/18926303/iterate-through-a-struct-in-go
      v := reflect.ValueOf(A{})
  
      for i := 0; i &lt; v.NumField(); i++ {
          foobar(v.Field(i).Interface()) // Passing each struct to the `foobar()` function
      }
  }
  </code></pre>
  
  <p>But it seems like I'm actually doing embedding instead of storing them, any suggestions please?</p>