title: Go- Copy all common fields between structs
body: <p>I have a database that stores JSON, and a server that provides an external API to whereby through an HTTP post, values in this database can be changed. The database is used by different processes internally, and as such have a common naming scheme.</p>
  
  <p>The keys the customer sees are different, but map 1:1 with the keys in the database (there are unexposed keys). For example:</p>
  
  <p>This is in the database:</p>
  
  <pre><code>{ "bit_size": 8, "secret_key": false }
  </code></pre>
  
  <p>And this is presented to the client:</p>
  
  <pre><code>{ "num_bits": 8 }
  </code></pre>
  
  <p>The API can change with respect to field names, but the database always has consistent keys.</p>
  
  <p>I have named the fields the same in the struct, with different flags to the json encoder:</p>
  
  <pre><code>type DB struct {
      NumBits int  `json:"bit_size"`
      Secret  bool `json:"secret_key"`
  }
  type User struct {
      NumBits int `json:"num_bits"`
  }
  </code></pre>
  
  <p>I'm using <code>encoding/json</code> to do the Marshal/Unmarshal.</p>
  
  <p>Is <code>reflect</code> the right tool for this? Is there an easier way since all of the keys are the same? I was thinking some kind of <code>memcpy</code> (if I kept the user fields in the same order).</p>