title: Golang convert list objects to string
body: <p>I have two structs:</p>
  
  <pre><code>type A struct {
      BankCode           string `json:"bankCode"`
      BankName           string `json:"bankName"`
  }
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>type B struct {
      A 
      extra           string `json:" extra"`
  }
  </code></pre>
  
  <p>And two slices:<br>
  <code>listsA []A</code> and <code>listsB []B</code>
  I want to get <code>bankCodes</code> from <code>listA</code> and <code>listB</code>. <code>bankcodes</code> only contains <code>bankcodes</code>. It is a <code>[]string</code></p>
  
  <p>It will be so easy as using two function.</p>
  
  <pre><code>func getBankCodes(data []A) []string {
      res := make([]string, len(data))
      for i := 0; i &lt; len(data); i++ {
          res[i] = data[i].BankCode
      }
      return res
  }
  
  func getBankCodes(data []B) []string {
      res := make([]string, len(data))
      for i := 0; i &lt; len(data); i++ {
          res[i] = data[i].BankCode
      }
      return res
  }
  </code></pre>
  
  <p>How to use one common function ?</p>