title: JSON to struct omitempty PATCH versus POST problem
body: <p>I am designing some REST API endpoints in Go. I use structs to define the object that handling in my API methods. These objects are sent as json and are stored in Firebase. Suppose I have the following simple struct:</p>
  <pre><code>type Person struct {
    Name        string `json:&quot;name&quot; firestore:&quot;name&quot;`
    Gender      string `json:&quot;gender,omitempty&quot; firestore:&quot;gender&quot;`
    Nationality string `json:&quot;nationality,omitempty&quot; firestore:&quot;nationality&quot;`
  }
  </code></pre>
  <p>And I have the following requirements:</p>
  <ul>
  <li>All fields are required when doing a <code>GET</code> request and reading from firebase.</li>
  <li>All fields are required when doing a <code>POST</code> request and serializing json body to struct.</li>
  <li>Only the <code>Name</code> field is required when doing a <code>PATCH</code> request and serializing json body to struct.</li>
  </ul>
  <p>What is the cleanest way to do serialization based on the same struct for all the methods? When doing the <code>GET</code> request there is no problem, since all the fields are and need to be present in Firebase. However, when I am going to use the <code>omitempty</code> tag for json serialization I cannot force the <code>POST</code> request to contain all fields and the <code>PATCH</code> request to contain only a subset of fields.</p>