Files
opencloud/vendor/github.com/bitly/go-simplejson/simplejson_reader.go
T
Jörn Friedrich Dreyer 076a3b0212 build(deps): bump go-micro to v4.11.4-0.20260929213538-cd412c159a26
Point the go-micro.dev/v4 replace at the latest main-v4 maintenance
branch commit in butonic/go-micro (cd412c15) instead of the v4.11.3
tag. The new base is upstream v4.11.1 plus the registry cache
node-TTL fixes (upstream #2715, #2736, #2740), the concurrent map
access fix (upstream #2794), plus further dependency updates and test
fixes on the maintenance branch.

The branch also modernizes go-micro's own go.mod (go 1.26, lego,
dario.cat/mergo v1, x/deque v2, ...), and MVS pulls the aligned
versions into this module: lego v4.35.2 -> lego/v5 v5.5.2,
go-jose/go-jose/v4 -> v4.1.5, gofrs/flock -> v0.13.1,
mattn/go-isatty -> v0.0.24, go.uber.org/zap -> v1.28.0, x/net ->
0.59.0, miekg/dns -> 1.1.73, moby api/client, ProtonMail/go-crypto
-> 1.5.2, klauspost/compress -> 1.20.1, gorilla/handlers -> 1.5.2,
gobwas/ws -> 1.4.0, nxadm/tail -> 1.4.11, ...

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
2026-10-01 11:14:15 +02:00

88 lines
2.3 KiB
Go

package simplejson
import (
"bytes"
"encoding/json"
"errors"
"io"
"reflect"
"strconv"
)
// Implements the json.Unmarshaler interface.
func (j *Json) UnmarshalJSON(p []byte) error {
dec := json.NewDecoder(bytes.NewBuffer(p))
dec.UseNumber()
return dec.Decode(&j.data)
}
// NewFromReader returns a *Json by decoding from an io.Reader
func NewFromReader(r io.Reader) (*Json, error) {
j := new(Json)
dec := json.NewDecoder(r)
dec.UseNumber()
err := dec.Decode(&j.data)
return j, err
}
// Float64 coerces into a float64
func (j *Json) Float64() (float64, error) {
switch j.data.(type) {
case json.Number:
return j.data.(json.Number).Float64()
case float32, float64:
return reflect.ValueOf(j.data).Float(), nil
case int, int8, int16, int32, int64:
return float64(reflect.ValueOf(j.data).Int()), nil
case uint, uint8, uint16, uint32, uint64:
return float64(reflect.ValueOf(j.data).Uint()), nil
}
return 0, errors.New("invalid value type")
}
// Int coerces into an int
func (j *Json) Int() (int, error) {
switch j.data.(type) {
case json.Number:
i, err := j.data.(json.Number).Int64()
return int(i), err
case float32, float64:
return int(reflect.ValueOf(j.data).Float()), nil
case int, int8, int16, int32, int64:
return int(reflect.ValueOf(j.data).Int()), nil
case uint, uint8, uint16, uint32, uint64:
return int(reflect.ValueOf(j.data).Uint()), nil
}
return 0, errors.New("invalid value type")
}
// Int64 coerces into an int64
func (j *Json) Int64() (int64, error) {
switch j.data.(type) {
case json.Number:
return j.data.(json.Number).Int64()
case float32, float64:
return int64(reflect.ValueOf(j.data).Float()), nil
case int, int8, int16, int32, int64:
return reflect.ValueOf(j.data).Int(), nil
case uint, uint8, uint16, uint32, uint64:
return int64(reflect.ValueOf(j.data).Uint()), nil
}
return 0, errors.New("invalid value type")
}
// Uint64 coerces into an uint64
func (j *Json) Uint64() (uint64, error) {
switch j.data.(type) {
case json.Number:
return strconv.ParseUint(j.data.(json.Number).String(), 10, 64)
case float32, float64:
return uint64(reflect.ValueOf(j.data).Float()), nil
case int, int8, int16, int32, int64:
return uint64(reflect.ValueOf(j.data).Int()), nil
case uint, uint8, uint16, uint32, uint64:
return reflect.ValueOf(j.data).Uint(), nil
}
return 0, errors.New("invalid value type")
}