MarshalJSON implements json.Marshaler.
()
| 559 | |
| 560 | // MarshalJSON implements json.Marshaler. |
| 561 | func (s *PrometheusData) MarshalJSON() ([]byte, error) { |
| 562 | switch s.ResultType { |
| 563 | case model.ValVector.String(): |
| 564 | res := struct { |
| 565 | ResultType string `json:"resultType"` |
| 566 | Data []Sample `json:"result"` |
| 567 | Stats *PrometheusResponseStats `json:"stats,omitempty"` |
| 568 | }{ |
| 569 | ResultType: s.ResultType, |
| 570 | Data: s.Result.GetVector().Samples, |
| 571 | Stats: s.Stats, |
| 572 | } |
| 573 | return json.Marshal(res) |
| 574 | case model.ValMatrix.String(): |
| 575 | res := struct { |
| 576 | ResultType string `json:"resultType"` |
| 577 | Data []SampleStream `json:"result"` |
| 578 | Stats *PrometheusResponseStats `json:"stats,omitempty"` |
| 579 | }{ |
| 580 | ResultType: s.ResultType, |
| 581 | Data: s.Result.GetMatrix().SampleStreams, |
| 582 | Stats: s.Stats, |
| 583 | } |
| 584 | return json.Marshal(res) |
| 585 | default: |
| 586 | return s.Result.GetRawBytes(), nil |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | // Adapted from https://github.com/prometheus/client_golang/blob/4b158abea9470f75b6f07460cdc2189b91914562/api/prometheus/v1/api.go#L84. |
| 591 | func UnmarshalSampleHistogramPairJSON(ptr unsafe.Pointer, iter *jsoniter.Iterator) { |
nothing calls this directly
no test coverage detected