I have an object that I receive:
{
"operation": "ACC00000001",
"prm": "23597250350000",
"conso_prod": "Conso",
"index_name": "BASE",
"index_value": "123456",
"timestamp": "2019-08-20T22:00:00Z"
}
The object I use is in a common lib, so it is shared by several services:
common.Measure:
type Measure struct {
Timestamp time.Time
Delta float64
Redistributed float64
IsProd bool
IndexValue uint32
IndexName string
Source string
}
and Meter:
type Meter struct {
ID string
Operation string
Unit string
Timestep time.Duration
Measures []Measure
}
But as the labels don't match, I must create another object MeasureFromJSON
which is the created based in the json I receive.
type MeasureFromJSON struct {
Operation string `json:"operation" binding:"required"`
Prm string `json:"prm"`
Conso_prod string `json:"conso_prod"`
Index_name string `json:"index_name"`
Index_value string `json:"index_value"`
Timestamp string `json:"timestamp"`
}
Thing is I don't like to use 2 models for the same entity, just because I have no JSON labels in common object. Is there a way to use the common models (meter.Measure
)?