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

Method UnmarshalJSON

model/value_float.go:41–51  ·  view source on GitHub ↗

UnmarshalJSON implements json.Unmarshaler.

(b []byte)

Source from the content-addressed store, hash-verified

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