title: How to pass different types as struct{} to function in GoLang?
body: <p>I want to write a function that takes different struct-types as 1 parameter. Also, I have to be sure, that in these structs is an <code>Id</code> field. So I want a function like this:</p>
  <pre><code>MyFunction(object *struct{ Id int })
  </code></pre>
  <p>I tried it with passing the struct as a <code>*struct{ Id int }</code> and an <code>interface{}</code> parameter.</p>
  <p>For example, I have these 2 struct-types:</p>
  <pre><code>type TableOne struct {
      Id   int
      name string
      date string
  }
  
  type TableTwo struct {
      Id      int
      address string
      athome  bool
  }
  </code></pre>
  <p>To save them in the database (using <code>reflection</code>) I have the following function:</p>
  <pre><code>func SaveMyTables(tablename string, obj *struct{ Id int }) {
      // ... Some code here
  
      if obj.Id != 0 {
          // ... Some code here
      }
  
      // ... Some code here
  }
  </code></pre>
  <p>I call the function like this:</p>
  <pre><code>obj := &amp;TableTwo{
      Id: 5
      address: &quot;some address&quot;
      athome: false
  }
  
  myPackage.Save(&quot;addresses&quot;, obj).
  </code></pre>
  <p>But I get this error:</p>
  <blockquote>
  <p>cannot use obj (type *mytables.TableTwo) as type *struct { Id int } in argument to myPackage.Save</p>
  </blockquote>