cast

package
v1.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToBool

func ToBool(v any) (bool, error)

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

func ToBoolDefault(v any, def bool) bool

ToBoolDefault is ToBool but returns def instead of an error on failure.

func ToDuration

func ToDuration(v any) (time.Duration, error)

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

func ToDurationDefault(v any, def time.Duration) time.Duration

ToDurationDefault is ToDuration but returns def instead of an error on failure.

func ToFloat64

func ToFloat64(v any) (float64, error)

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

func ToFloat64Default(v any, def float64) float64

ToFloat64Default is ToFloat64 but returns def instead of an error on failure.

func ToInt

func ToInt(v any) (int, error)

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

func ToIntDefault(v any, def int) int

ToIntDefault is ToInt but returns def instead of an error on failure.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL