title: Empty Interfaces in Golang
body: <p><strong>Edit</strong>: This is <strong>not</strong> the right way to use interfaces in Go. The purpose of this question is for me to understand how empty interfaces work in Go.</p>
  
  <p>If all types in Go implement <code>interface{}</code> (empty interface), why can't I access the <code>name</code> field in the <code>Cat</code> and <code>Dog</code> structs? How can I get access to the name field of each struct through the function sayHi()?</p>
  
  <pre><code>package main
  
  import (
      "fmt"
  )
  
  func sayHi(i interface{}) {
  
      fmt.Println(i, "says hello")
  
      // Not understanding this error message
      fmt.Println(i.name) //  i.name undefined (type interface {} is interface with no methods)
  } 
  
  type Dog struct{
      name string
  }
  type Cat struct{
      name string
  }
  
  func main() {
      d := Dog{"Sparky"}
      c := Cat{"Garfield"}
  
      sayHi(d) // {Sparky} says hello
      sayHi(c) // {Garfield} says hello
  }
  </code></pre>