title: How can two different types implement the same method in golang using interfaces?
body: <p>Say I have two structs:</p>
  
  <pre><code>type First struct {
      str string
  }
  type Second struct {
      str string
  }
  </code></pre>
  
  <p>And I want both of them to implement interface A:</p>
  
  <pre><code>type A interface {
      PrintStr() //print First.str or Second.str
  }
  </code></pre>
  
  <p>It seems redundant to have an implementation for both First and Second structs like so:</p>
  
  <pre><code>func (f First) PrintStr() {
      fmt.Print(f.str)
  }
  
  func (s Second) PrintStr() {
      fmt.Print(s.str)
  }
  </code></pre>
  
  <p>Is there a way I can have one implementation for all the structs implementing interface A? Something like this, but it doesn't seem to work:</p>
  
  <pre><code>func (a A) PrintStr() {
      fmt.Print(a.str)
  }
  </code></pre>
  
  <p>Thank you! </p>