title: Go "inheritance" - using anonymous type in a struct as a method parameter
body: <p>I'm trying to firm up the concept of inheritence that Go provides (rather "composition" than pure inheritence, perhaps). However, I'm failing to grasp why I can't use the "parent" type as a <code>func</code> parameter to produce a generic function that acts on the parameter.</p>
  
  <pre><code>package main
  
  import "log"
  
  type Animal struct {
      Colour string
      Name string
  }
  
  type Dog struct {
      Animal
  }
  
  func PrintColour(a *Animal) {
      log.Printf("%s\n", a.Colour)
  }
  
  
  func main () {
      a := new (Animal)
      a.Colour = "Void"
      d := new (Dog)
      d.Colour = "Black"
  
      PrintColour(a)
      PrintColour(d)
  }
  </code></pre>
  
  <p>Assuming my understanding's incorrect, how can I achieve what I want in Go?</p>
  
  <p><strong>Edit</strong>
  Note: </p>
  
  <ul>
  <li><p>I don't want to attach the behaviour to the struct</p></li>
  <li><p>I'd like to keep the pointer type as the method parameter because I'm working separately on a pet project and this requires I manipulate the struct passed in before then acting on it.</p></li>
  <li><p>In reality my <code>Dog</code> struct would have additional fields/members; hopefully this doesn't muddy the water further</p></li>
  </ul>