|
|
@ -16,10 +16,15 @@ type Value struct { |
|
|
|
} |
|
|
|
|
|
|
|
func (v Value) MarshalJSON() ([]byte, error) { |
|
|
|
return json.Marshal(v.AsInterface()) |
|
|
|
b, err := json.Marshal(v.AsInterface()) |
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("marshal err: %w", err) |
|
|
|
} |
|
|
|
|
|
|
|
return b, nil |
|
|
|
} |
|
|
|
|
|
|
|
//nolint: gocyclo
|
|
|
|
//nolint: gocyclo,gomnd,cyclop
|
|
|
|
func (v Value) String() string { |
|
|
|
switch { |
|
|
|
case v.vtype.IsArray(), v.vtype.IsAny(): |
|
|
@ -57,7 +62,7 @@ func (v Value) String() string { |
|
|
|
return fmt.Sprintf("%+v", v.AsInterface()) |
|
|
|
} |
|
|
|
|
|
|
|
//nolint: gocyclo
|
|
|
|
//nolint: gocyclo,cyclop
|
|
|
|
func (v Value) AsInterface() interface{} { |
|
|
|
switch { |
|
|
|
case v.vtype.IsArray(): |
|
|
@ -288,13 +293,20 @@ func (v Value) asError() error { |
|
|
|
} |
|
|
|
|
|
|
|
func nilValue(t Type) Value { |
|
|
|
return Value{vtype: t | TypeNil} |
|
|
|
return Value{ |
|
|
|
vtype: t | TypeNil, |
|
|
|
value: nil, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func stringValue(v string) Value { |
|
|
|
return Value{ |
|
|
|
stringly: v, |
|
|
|
vtype: TypeString, |
|
|
|
numeric: 0, |
|
|
|
value: nil, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -302,6 +314,8 @@ func stringsValue(v []string) Value { |
|
|
|
return Value{ |
|
|
|
value: v, |
|
|
|
vtype: TypeString | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -318,11 +332,16 @@ func boolValue(b bool) Value { |
|
|
|
return Value{ |
|
|
|
numeric: 1, |
|
|
|
vtype: TypeBool, |
|
|
|
value: nil, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return Value{ |
|
|
|
vtype: TypeBool, |
|
|
|
value: nil, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -330,6 +349,8 @@ func boolsValue(b []bool) Value { |
|
|
|
return Value{ |
|
|
|
value: b, |
|
|
|
vtype: TypeBool | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -345,6 +366,8 @@ func intValue(i int) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeInt, |
|
|
|
numeric: uint64(i), |
|
|
|
value: nil, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -352,6 +375,8 @@ func intsValue(i []int) Value { |
|
|
|
return Value{ |
|
|
|
value: i, |
|
|
|
vtype: TypeInt | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -367,6 +392,8 @@ func int8Value(i int8) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeInt8, |
|
|
|
numeric: uint64(i), |
|
|
|
value: nil, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -374,6 +401,8 @@ func int8sValue(i []int8) Value { |
|
|
|
return Value{ |
|
|
|
value: i, |
|
|
|
vtype: TypeInt8 | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -389,6 +418,8 @@ func int16Value(i int16) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeInt16, |
|
|
|
numeric: uint64(i), |
|
|
|
value: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -396,6 +427,8 @@ func int16sValue(i []int16) Value { |
|
|
|
return Value{ |
|
|
|
value: i, |
|
|
|
vtype: TypeInt16 | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -411,6 +444,8 @@ func int32Value(i int32) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeInt32, |
|
|
|
numeric: uint64(i), |
|
|
|
value: nil, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -418,6 +453,8 @@ func int32sValue(i []int32) Value { |
|
|
|
return Value{ |
|
|
|
value: i, |
|
|
|
vtype: TypeInt32 | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -433,6 +470,8 @@ func int64Value(i int64) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeInt64, |
|
|
|
numeric: uint64(i), |
|
|
|
value: nil, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -440,6 +479,8 @@ func int64sValue(i []int64) Value { |
|
|
|
return Value{ |
|
|
|
value: i, |
|
|
|
vtype: TypeInt64 | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -455,6 +496,8 @@ func uintValue(i uint) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeUint, |
|
|
|
numeric: uint64(i), |
|
|
|
value: nil, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -462,6 +505,8 @@ func uintsValue(i []uint) Value { |
|
|
|
return Value{ |
|
|
|
value: i, |
|
|
|
vtype: TypeUint | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -477,6 +522,8 @@ func uint8Value(i uint8) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeUint8, |
|
|
|
numeric: uint64(i), |
|
|
|
value: nil, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -484,6 +531,8 @@ func uint8sValue(i []uint8) Value { |
|
|
|
return Value{ |
|
|
|
value: i, |
|
|
|
vtype: TypeUint8 | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -499,6 +548,8 @@ func uint16Value(i uint16) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeUint16, |
|
|
|
numeric: uint64(i), |
|
|
|
value: nil, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -506,6 +557,8 @@ func uint16sValue(i []uint16) Value { |
|
|
|
return Value{ |
|
|
|
value: i, |
|
|
|
vtype: TypeUint16 | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -521,6 +574,8 @@ func uint32Value(i uint32) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeUint32, |
|
|
|
numeric: uint64(i), |
|
|
|
value: nil, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -528,6 +583,8 @@ func uint32sValue(i []uint32) Value { |
|
|
|
return Value{ |
|
|
|
value: i, |
|
|
|
vtype: TypeUint32 | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -543,6 +600,8 @@ func uint64Value(i uint64) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeUint64, |
|
|
|
numeric: i, |
|
|
|
value: nil, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -550,6 +609,8 @@ func uint64sValue(i []uint64) Value { |
|
|
|
return Value{ |
|
|
|
value: i, |
|
|
|
vtype: TypeUint64 | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -565,6 +626,8 @@ func float32Value(i float32) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeFloat32, |
|
|
|
numeric: uint64(math.Float32bits(i)), |
|
|
|
value: nil, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -572,6 +635,8 @@ func float32sValue(i []float32) Value { |
|
|
|
return Value{ |
|
|
|
value: i, |
|
|
|
vtype: TypeFloat32 | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -587,6 +652,8 @@ func float64Value(i float64) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeFloat64, |
|
|
|
numeric: math.Float64bits(i), |
|
|
|
value: nil, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -594,6 +661,8 @@ func float64sValue(i []float64) Value { |
|
|
|
return Value{ |
|
|
|
value: i, |
|
|
|
vtype: TypeFloat64 | TypeArray, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -609,6 +678,8 @@ func complex64Value(in complex64) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeComplex64, |
|
|
|
value: in, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -616,6 +687,8 @@ func complex64sValue(in []complex64) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeComplex64 | TypeArray, |
|
|
|
value: in, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -631,6 +704,8 @@ func complex128Value(in complex128) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeComplex64, |
|
|
|
value: in, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -638,6 +713,8 @@ func complex128sValue(in []complex128) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeComplex128 | TypeArray, |
|
|
|
value: in, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -652,6 +729,8 @@ func complex128pValue(in *complex128) Value { |
|
|
|
func uintptrValue(in uintptr) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeUintptr, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
value: in, |
|
|
|
} |
|
|
|
} |
|
|
@ -660,6 +739,8 @@ func uintptrsValue(in []uintptr) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeUintptr | TypeArray, |
|
|
|
value: in, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -675,6 +756,8 @@ func bytesValue(in []byte) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeBinary, |
|
|
|
value: in, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -682,6 +765,8 @@ func durationValue(in time.Duration) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeDuration, |
|
|
|
value: in, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -689,6 +774,8 @@ func durationsValue(in []time.Duration) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeDuration | TypeArray, |
|
|
|
value: in, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -717,6 +804,7 @@ func formatTimeValue(format string, in time.Time) Value { |
|
|
|
vtype: TypeTime, |
|
|
|
value: in, |
|
|
|
stringly: format, |
|
|
|
numeric: 0, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -725,6 +813,7 @@ func formatTimesValue(format string, in []time.Time) Value { |
|
|
|
vtype: TypeTime | TypeArray, |
|
|
|
value: in, |
|
|
|
stringly: format, |
|
|
|
numeric: 0, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -741,6 +830,8 @@ func errorValue(in error) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeError, |
|
|
|
value: in, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -751,5 +842,7 @@ func errorsValue(in []error) Value { |
|
|
|
return Value{ |
|
|
|
vtype: TypeError | TypeArray, |
|
|
|
value: in, |
|
|
|
numeric: 0, |
|
|
|
stringly: "", |
|
|
|
} |
|
|
|
} |
|
|
|