|
|
@ -40,7 +40,7 @@ func (v *atomicValue) Bool() (bool, error) { |
|
|
|
switch val := v.Load().(type) { |
|
|
|
switch val := v.Load().(type) { |
|
|
|
case bool: |
|
|
|
case bool: |
|
|
|
return val, nil |
|
|
|
return val, nil |
|
|
|
case int, int32, int64, float64, string: |
|
|
|
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, string: |
|
|
|
return strconv.ParseBool(fmt.Sprint(val)) |
|
|
|
return strconv.ParseBool(fmt.Sprint(val)) |
|
|
|
} |
|
|
|
} |
|
|
|
return false, fmt.Errorf("type assert to %v failed", reflect.TypeOf(v.Load())) |
|
|
|
return false, fmt.Errorf("type assert to %v failed", reflect.TypeOf(v.Load())) |
|
|
@ -50,10 +50,26 @@ func (v *atomicValue) Int() (int64, error) { |
|
|
|
switch val := v.Load().(type) { |
|
|
|
switch val := v.Load().(type) { |
|
|
|
case int: |
|
|
|
case int: |
|
|
|
return int64(val), nil |
|
|
|
return int64(val), nil |
|
|
|
|
|
|
|
case int8: |
|
|
|
|
|
|
|
return int64(val), nil |
|
|
|
|
|
|
|
case int16: |
|
|
|
|
|
|
|
return int64(val), nil |
|
|
|
case int32: |
|
|
|
case int32: |
|
|
|
return int64(val), nil |
|
|
|
return int64(val), nil |
|
|
|
case int64: |
|
|
|
case int64: |
|
|
|
return val, nil |
|
|
|
return val, nil |
|
|
|
|
|
|
|
case uint: |
|
|
|
|
|
|
|
return int64(val), nil |
|
|
|
|
|
|
|
case uint8: |
|
|
|
|
|
|
|
return int64(val), nil |
|
|
|
|
|
|
|
case uint16: |
|
|
|
|
|
|
|
return int64(val), nil |
|
|
|
|
|
|
|
case uint32: |
|
|
|
|
|
|
|
return int64(val), nil |
|
|
|
|
|
|
|
case uint64: |
|
|
|
|
|
|
|
return int64(val), nil |
|
|
|
|
|
|
|
case float32: |
|
|
|
|
|
|
|
return int64(val), nil |
|
|
|
case float64: |
|
|
|
case float64: |
|
|
|
return int64(val), nil |
|
|
|
return int64(val), nil |
|
|
|
case string: |
|
|
|
case string: |
|
|
@ -90,14 +106,30 @@ func (v *atomicValue) Map() (map[string]Value, error) { |
|
|
|
|
|
|
|
|
|
|
|
func (v *atomicValue) Float() (float64, error) { |
|
|
|
func (v *atomicValue) Float() (float64, error) { |
|
|
|
switch val := v.Load().(type) { |
|
|
|
switch val := v.Load().(type) { |
|
|
|
case float64: |
|
|
|
|
|
|
|
return val, nil |
|
|
|
|
|
|
|
case int: |
|
|
|
case int: |
|
|
|
return float64(val), nil |
|
|
|
return float64(val), nil |
|
|
|
|
|
|
|
case int8: |
|
|
|
|
|
|
|
return float64(val), nil |
|
|
|
|
|
|
|
case int16: |
|
|
|
|
|
|
|
return float64(val), nil |
|
|
|
case int32: |
|
|
|
case int32: |
|
|
|
return float64(val), nil |
|
|
|
return float64(val), nil |
|
|
|
case int64: |
|
|
|
case int64: |
|
|
|
return float64(val), nil |
|
|
|
return float64(val), nil |
|
|
|
|
|
|
|
case uint: |
|
|
|
|
|
|
|
return float64(val), nil |
|
|
|
|
|
|
|
case uint8: |
|
|
|
|
|
|
|
return float64(val), nil |
|
|
|
|
|
|
|
case uint16: |
|
|
|
|
|
|
|
return float64(val), nil |
|
|
|
|
|
|
|
case uint32: |
|
|
|
|
|
|
|
return float64(val), nil |
|
|
|
|
|
|
|
case uint64: |
|
|
|
|
|
|
|
return float64(val), nil |
|
|
|
|
|
|
|
case float32: |
|
|
|
|
|
|
|
return float64(val), nil |
|
|
|
|
|
|
|
case float64: |
|
|
|
|
|
|
|
return val, nil |
|
|
|
case string: |
|
|
|
case string: |
|
|
|
return strconv.ParseFloat(val, 64) //nolint:gomnd
|
|
|
|
return strconv.ParseFloat(val, 64) //nolint:gomnd
|
|
|
|
} |
|
|
|
} |
|
|
@ -108,7 +140,7 @@ func (v *atomicValue) String() (string, error) { |
|
|
|
switch val := v.Load().(type) { |
|
|
|
switch val := v.Load().(type) { |
|
|
|
case string: |
|
|
|
case string: |
|
|
|
return val, nil |
|
|
|
return val, nil |
|
|
|
case bool, int, int32, int64, float64: |
|
|
|
case bool, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64: |
|
|
|
return fmt.Sprint(val), nil |
|
|
|
return fmt.Sprint(val), nil |
|
|
|
case []byte: |
|
|
|
case []byte: |
|
|
|
return string(val), nil |
|
|
|
return string(val), nil |
|
|
|