mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update buildkit with typed errors support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
77
vendor/github.com/xeipuuv/gojsonschema/utils.go
generated
vendored
77
vendor/github.com/xeipuuv/gojsonschema/utils.go
generated
vendored
@ -27,15 +27,13 @@ package gojsonschema
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func isKind(what interface{}, kinds ...reflect.Kind) bool {
|
||||
target := what
|
||||
if isJsonNumber(what) {
|
||||
if isJSONNumber(what) {
|
||||
// JSON Numbers are strings!
|
||||
target = *mustBeNumber(what)
|
||||
}
|
||||
@ -62,7 +60,17 @@ func isStringInSlice(s []string, what string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func marshalToJsonString(value interface{}) (*string, error) {
|
||||
// indexStringInSlice returns the index of the first instance of 'what' in s or -1 if it is not found in s.
|
||||
func indexStringInSlice(s []string, what string) int {
|
||||
for i := range s {
|
||||
if s[i] == what {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func marshalToJSONString(value interface{}) (*string, error) {
|
||||
|
||||
mBytes, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
@ -80,7 +88,7 @@ func marshalWithoutNumber(value interface{}) (*string, error) {
|
||||
// One way to eliminate these differences is to decode and encode the JSON one more time without Decoder.UseNumber
|
||||
// so that these differences in representation are removed
|
||||
|
||||
jsonString, err := marshalToJsonString(value)
|
||||
jsonString, err := marshalToJSONString(value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -92,10 +100,10 @@ func marshalWithoutNumber(value interface{}) (*string, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return marshalToJsonString(document)
|
||||
return marshalToJSONString(document)
|
||||
}
|
||||
|
||||
func isJsonNumber(what interface{}) bool {
|
||||
func isJSONNumber(what interface{}) bool {
|
||||
|
||||
switch what.(type) {
|
||||
|
||||
@ -106,11 +114,11 @@ func isJsonNumber(what interface{}) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func checkJsonInteger(what interface{}) (isInt bool) {
|
||||
func checkJSONInteger(what interface{}) (isInt bool) {
|
||||
|
||||
jsonNumber := what.(json.Number)
|
||||
|
||||
bigFloat, isValidNumber := new(big.Float).SetString(string(jsonNumber))
|
||||
bigFloat, isValidNumber := new(big.Rat).SetString(string(jsonNumber))
|
||||
|
||||
return isValidNumber && bigFloat.IsInt()
|
||||
|
||||
@ -118,26 +126,17 @@ func checkJsonInteger(what interface{}) (isInt bool) {
|
||||
|
||||
// same as ECMA Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER
|
||||
const (
|
||||
max_json_float = float64(1<<53 - 1) // 9007199254740991.0 2^53 - 1
|
||||
min_json_float = -float64(1<<53 - 1) //-9007199254740991.0 -2^53 - 1
|
||||
maxJSONFloat = float64(1<<53 - 1) // 9007199254740991.0 2^53 - 1
|
||||
minJSONFloat = -float64(1<<53 - 1) //-9007199254740991.0 -2^53 - 1
|
||||
)
|
||||
|
||||
func isFloat64AnInteger(f float64) bool {
|
||||
|
||||
if math.IsNaN(f) || math.IsInf(f, 0) || f < min_json_float || f > max_json_float {
|
||||
return false
|
||||
}
|
||||
|
||||
return f == float64(int64(f)) || f == float64(uint64(f))
|
||||
}
|
||||
|
||||
func mustBeInteger(what interface{}) *int {
|
||||
|
||||
if isJsonNumber(what) {
|
||||
if isJSONNumber(what) {
|
||||
|
||||
number := what.(json.Number)
|
||||
|
||||
isInt := checkJsonInteger(number)
|
||||
isInt := checkJSONInteger(number)
|
||||
|
||||
if isInt {
|
||||
|
||||
@ -148,9 +147,6 @@ func mustBeInteger(what interface{}) *int {
|
||||
|
||||
int32Value := int(int64Value)
|
||||
return &int32Value
|
||||
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
@ -158,45 +154,20 @@ func mustBeInteger(what interface{}) *int {
|
||||
return nil
|
||||
}
|
||||
|
||||
func mustBeNumber(what interface{}) *big.Float {
|
||||
func mustBeNumber(what interface{}) *big.Rat {
|
||||
|
||||
if isJsonNumber(what) {
|
||||
if isJSONNumber(what) {
|
||||
number := what.(json.Number)
|
||||
float64Value, success := new(big.Float).SetString(string(number))
|
||||
float64Value, success := new(big.Rat).SetString(string(number))
|
||||
if success {
|
||||
return float64Value
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// formats a number so that it is displayed as the smallest string possible
|
||||
func resultErrorFormatJsonNumber(n json.Number) string {
|
||||
|
||||
if int64Value, err := n.Int64(); err == nil {
|
||||
return fmt.Sprintf("%d", int64Value)
|
||||
}
|
||||
|
||||
float64Value, _ := n.Float64()
|
||||
|
||||
return fmt.Sprintf("%g", float64Value)
|
||||
}
|
||||
|
||||
// formats a number so that it is displayed as the smallest string possible
|
||||
func resultErrorFormatNumber(n float64) string {
|
||||
|
||||
if isFloat64AnInteger(n) {
|
||||
return fmt.Sprintf("%d", int64(n))
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%g", n)
|
||||
}
|
||||
|
||||
func convertDocumentNode(val interface{}) interface{} {
|
||||
|
||||
if lval, ok := val.([]interface{}); ok {
|
||||
|
Reference in New Issue
Block a user