Skip to content

Commit

Permalink
Remove sampleHistogramPairPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
zenador committed Jan 5, 2023
1 parent b316e2e commit 41cdb02
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions model/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ func (s Sample) MarshalJSON() ([]byte, error) {
return json.Marshal(&v)
}

type sampleHistogramPairPtr struct {
Timestamp Time
Histogram *SampleHistogram
}

func (s *sampleHistogramPairPtr) UnmarshalJSON(buf []byte) error {
tmp := []interface{}{&s.Timestamp, &s.Histogram}
wantLen := len(tmp)
Expand All @@ -118,18 +113,18 @@ func (s *sampleHistogramPairPtr) UnmarshalJSON(buf []byte) error {
// UnmarshalJSON implements json.Unmarshaler.
func (s *Sample) UnmarshalJSON(b []byte) error {
v := struct {
Metric Metric `json:"metric"`
Value SamplePair `json:"value"`
Histogram sampleHistogramPairPtr `json:"histogram"`
Metric Metric `json:"metric"`
Value SamplePair `json:"value"`
Histogram *SampleHistogramPair `json:"histogram"`
}{
Metric: s.Metric,
Value: SamplePair{
Timestamp: s.Timestamp,
Value: s.Value,
},
Histogram: sampleHistogramPairPtr{
Histogram: &SampleHistogramPair{
Timestamp: s.Timestamp,
Histogram: s.Histogram,
Histogram: *s.Histogram,
},
}

Expand All @@ -138,9 +133,9 @@ func (s *Sample) UnmarshalJSON(b []byte) error {
}

s.Metric = v.Metric
if v.Histogram.Histogram != nil {
if v.Histogram != nil {
s.Timestamp = v.Histogram.Timestamp
s.Histogram = v.Histogram.Histogram
s.Histogram = &v.Histogram.Histogram
} else {
s.Timestamp = v.Value.Timestamp
s.Value = v.Value.Value
Expand Down

0 comments on commit 41cdb02

Please sign in to comment.