Index
- func Bool(val any) bool
- func Float64(val any) float64
- func Int(val any) int
- func Map(value any) map[string]any
- func Ptr[T any](val T) *T
- func PtrRuntime(val any) any
- func String(val any) string
func Bool
func Bool(val any) bool
Bool converts the given value to boolean. Should be used in a known environment, when values are expected to be correct. Panics in case of failure.
Usage:
conv.Bool(5.4) // true
conv.Bool("") // false
conv.Bool(0) // false
conv.Bool(struct{}) // panic!
func Float64
func Float64(val any) float64
Float64 converts the given value to float64. Should be used in a known environment, when values are expected to be correct. Panics in case of failure.
Usage:
conv.Float64("5") // 5.0
conv.Float64(true) // 1.0
conv.Float64("qwe") // panic!
func Int
func Int(val any) int
Int converts the given value to int. Should be used in a known environment, when values are expected to be correct. Panics in case of failure.
Usage:
conv.Int("123") // 123
conv.Int("asd") // panic!
func Map
func Map(value any) map[string]any
Map transforms a given json-marshalable value (usually it's a struct) to the map[string]any.
Usage:
type Example struct{
A string
B string
}
conv.Map(Example{ // map[string]any{"A": 1, "B": 2}
A: "1",
B: "2",
})
func Ptr
func Ptr[T any](val T) *T
Ptr makes a pointer for a given value.
Usage:
conv.Ptr(1) // *int{1}
func PtrRuntime
func PtrRuntime(val any) any
PtrRuntime is a runtime version of conv.Ptr.
Usage:
// Please note, you'll receive "any" type which you'll need to cast.
conv.PtrRuntime(1) // any, which holds *int{1}
func String
func String(val any) string
String converts the given value to a string. Uses fmt.Sprintf("%v", val) as fallback for unknown types.
Usage:
conv.String(true) // "true"
conv.String(1) // "1"
Generated by gomarkdoc