MCPcopy
hub / github.com/getsops/sops / normalizeJSONNumber

Function normalizeJSONNumber

stores/json/store.go:139–152  ·  view source on GitHub ↗

normalizeJSONNumber converts a json.Number scalar (produced because the decoder runs with UseNumber) into an int for integers within the int64 range and a float64 otherwise. Non-number tokens are returned unchanged; a number representable as neither returns the json.Number.Float64 error.

(t interface{})

Source from the content-addressed store, hash-verified

137// and a float64 otherwise. Non-number tokens are returned unchanged; a number
138// representable as neither returns the json.Number.Float64 error.
139func normalizeJSONNumber(t interface{}) (interface{}, error) {
140 n, ok := t.(json.Number)
141 if !ok {
142 return t, nil
143 }
144 if i, err := n.Int64(); err == nil {
145 return int(i), nil
146 }
147 f, err := n.Float64()
148 if err != nil {
149 return nil, err
150 }
151 return f, nil
152}
153
154var errEndOfObject = fmt.Errorf("End of object")
155

Callers 3

sliceFromJSONDecoderMethod · 0.85
treeBranchFromJSONMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected