title: How to organize similar struct to avoid duplication without sacrificating memory
body: <p>I have to refactor a code, and I don't know how to best define my structs.</p>
  
  <p>I have a list of meters <code>[]Meter</code></p>
  
  <p>With <code>Meter</code></p>
  
  <pre><code>type Meter struct {
      ID          string    `json:"meter_id"`
      ConsoProd   string    `json:"conso_prod"`
      OperationID string    `json:"op_id"`
      Measures    []Measure `json :"measures"`
  }
  </code></pre>
  
  <p>The 3 first field will always be here, but Measure has several variants, depending the step in the process.</p>
  
  <p>Here is the general <code>Measure</code> struct:</p>
  
  <pre><code>// Measure is a measure from a Meter
      type Measure struct {
          IndexName     string    `json:"index_name"`
          IndexValue    int       `json:"index_value"`
          Timestamp     time.Time `json:"timestamp"`
          Delta         float64   `json:"delta"`
          Redistributed float64   `json:"redistributed,omitempty"` // We don t need the redistributed field in Raw Measure
      }
  </code></pre>
  
  <p>First, we get the 'raw value'</p>
  
  <pre><code>type RawMeasure struct {
      IndexName     string    `json:"index_name"`
      IndexValue    int       `json:"index_value"`
      Timestamp     time.Time `json:"timestamp"`
      Delta         float64   `json:"delta"`
  }
  </code></pre>
  
  <p>Then we will calculate the redistributed, and store it into the <code>redistributed</code> field </p>
  
  <p>The measure will never have a redistributed.</p>
  
  <p>Also, I have 2 data sources. If Data comes from source2, it will never have IndexName / IndexValue</p>
  
  <pre><code>type RawMeasureFromSource2 struct {
      Timestamp     time.Time `json:"timestamp"`
      Delta         float64   `json:"delta"`
  }
  </code></pre>
  
  <p>Here we can see I could create several structs: (RawMeasure, RawMeasureFromSource2, Measure) and then I should create other 3 Meters vars. </p>
  
  <p>As I will manage a lot of data, I need to be careful optimizing memory, but it seems it will complicate my code a lot.</p>
  
  <p>Is there a way to get both a simple code, and optimized memory usage?</p>