mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-05 11:11:13 +00:00
Upgraded from 99c19923, branch release-3.0. This required fetching or upgrading the following: * k8s.io/api to kubernetes-1.9.1 * k8s.io/apimachinery to kubernetes-1.9.1 * github.com/juju/ratelimit to 1.0.1 * github.com/spf13/pflag to 4c012f6d Also, update Scope's imports/function calls to be compatible with the new client.
32 lines
652 B
Go
32 lines
652 B
Go
package jsoniter
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
)
|
|
|
|
type Number string
|
|
|
|
// String returns the literal text of the number.
|
|
func (n Number) String() string { return string(n) }
|
|
|
|
// Float64 returns the number as a float64.
|
|
func (n Number) Float64() (float64, error) {
|
|
return strconv.ParseFloat(string(n), 64)
|
|
}
|
|
|
|
// Int64 returns the number as an int64.
|
|
func (n Number) Int64() (int64, error) {
|
|
return strconv.ParseInt(string(n), 10, 64)
|
|
}
|
|
|
|
func CastJsonNumber(val interface{}) (string, bool) {
|
|
switch typedVal := val.(type) {
|
|
case json.Number:
|
|
return string(typedVal), true
|
|
case Number:
|
|
return string(typedVal), true
|
|
}
|
|
return "", false
|
|
}
|