Documentation
¶
Index ¶
- func ToBool(v any) (bool, error)
- func ToBoolDefault(v any, def bool) bool
- func ToDuration(v any) (time.Duration, error)
- func ToDurationDefault(v any, def time.Duration) time.Duration
- func ToFloat64(v any) (float64, error)
- func ToFloat64Default(v any, def float64) float64
- func ToInt(v any) (int, error)
- func ToIntDefault(v any, def int) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToBool ¶
ToBool converts a value of any type to a boolean. It supports boolean types, string representations of booleans, and numeric types (0 is false, non-zero is true). Returns an error if the conversion is not possible.
func ToBoolDefault ¶
ToBoolDefault converts a value of any type to a boolean, returning a default value if conversion fails. It uses ToBool for the conversion and returns the provided default value if an error occurs.
func ToDuration ¶
ToDuration converts a value of any type to a time.Duration. It supports time.Duration, string representations (using time.ParseDuration), and numeric types (interpreted as seconds). Returns an error if the conversion is not possible.
func ToDurationDefault ¶
ToDurationDefault converts a value of any type to a time.Duration, returning a default value if conversion fails. It uses ToDuration for the conversion and returns the provided default value if an error occurs.
func ToFloat64 ¶
ToFloat64 converts a value of any type to a float64. It supports various numeric types, string representations of floats, and fmt.Stringer implementations. Returns an error if the conversion is not possible.
func ToFloat64Default ¶
ToFloat64Default converts a value of any type to a float64, returning a default value if conversion fails. It uses ToFloat64 for the conversion and returns the provided default value if an error occurs.
func ToInt ¶
ToInt converts a value of any type to an int. It supports various numeric types, string representations of integers, and fmt.Stringer implementations. Returns an error if the conversion is not possible or if the value overflows.
func ToIntDefault ¶
ToIntDefault converts a value of any type to an int, returning a default value if conversion fails. It uses ToInt for the conversion and returns the provided default value if an error occurs.
Types ¶
This section is empty.