MCPcopy Create free account
hub / github.com/prometheus/common / UnmarshalJSON

Method UnmarshalJSON

model/value_float.go:40–50  ·  view source on GitHub ↗

UnmarshalJSON implements json.Unmarshaler.

(b []byte)

Source from the content-addressed store, hash-verified

38
39// UnmarshalJSON implements json.Unmarshaler.
40func (v *SampleValue) UnmarshalJSON(b []byte) error {
41 if len(b) < 2 || b[0] != '"' || b[len(b)-1] != '"' {
42 return fmt.Errorf("sample value must be a quoted string")
43 }
44 f, err := strconv.ParseFloat(string(b[1:len(b)-1]), 64)
45 if err != nil {
46 return err
47 }
48 *v = SampleValue(f)
49 return nil
50}
51
52// Equal returns true if the value of v and o is equal or if both are NaN. Note
53// that v==o is false if both are NaN. If you want the conventional float

Callers

nothing calls this directly

Calls 1

SampleValueTypeAlias · 0.85

Tested by

no test coverage detected