cast

package
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package cast provides easy and safe casting in Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringToDate

func StringToDate(s string) (time.Time, error)

StringToDate attempts to parse a string into a time.Time type using a predefined list of formats. If no suitable format is found, an error is returned.

func StringToDateInDefaultLocation

func StringToDateInDefaultLocation(s string, location *time.Location) (time.Time, error)

StringToDateInDefaultLocation casts an empty interface to a time.Time, interpreting inputs without a timezone to be in the given location, or the local timezone if nil.

func ToBool

func ToBool(i any) bool

ToBool casts an interface to a bool type.

func ToBoolE

func ToBoolE(i any) (bool, error)

ToBoolE casts an interface to a bool type.

func ToBoolSlice

func ToBoolSlice(i any) []bool

ToBoolSlice casts an interface to a []bool type.

func ToBoolSliceE

func ToBoolSliceE(i any) ([]bool, error)

ToBoolSliceE casts an interface to a []bool type.

func ToDuration

func ToDuration(i any) time.Duration

ToDuration casts an interface to a time.Duration type.

func ToDurationE

func ToDurationE(i any) (d time.Duration, err error)

ToDurationE casts an interface to a time.Duration type.

func ToDurationSlice

func ToDurationSlice(i any) []time.Duration

ToDurationSlice casts an interface to a []time.Duration type.

func ToDurationSliceE

func ToDurationSliceE(i any) ([]time.Duration, error)

ToDurationSliceE casts an interface to a []time.Duration type.

func ToFloat32

func ToFloat32(i any) float32

ToFloat32 casts an interface to a float32 type.

func ToFloat32E

func ToFloat32E(i any) (float32, error)

ToFloat32E casts an interface to a float32 type.

func ToFloat64

func ToFloat64(i any) float64

ToFloat64 casts an interface to a float64 type.

func ToFloat64E

func ToFloat64E(i any) (float64, error)

ToFloat64E casts an interface to a float64 type.

func ToInt

func ToInt(i any) int

ToInt casts an interface to an int type.

func ToInt16

func ToInt16(i any) int16

ToInt16 casts an interface to an int16 type.

func ToInt16E

func ToInt16E(i any) (int16, error)

ToInt16E casts an interface to an int16 type.

func ToInt32

func ToInt32(i any) int32

ToInt32 casts an interface to an int32 type.

func ToInt32E

func ToInt32E(i any) (int32, error)

ToInt32E casts an interface to an int32 type.

func ToInt64

func ToInt64(i any) int64

ToInt64 casts an interface to an int64 type.

func ToInt64E

func ToInt64E(i any) (int64, error)

ToInt64E casts an interface to an int64 type.

func ToInt8

func ToInt8(i any) int8

ToInt8 casts an interface to an int8 type.

func ToInt8E

func ToInt8E(i any) (int8, error)

ToInt8E casts an interface to an int8 type.

func ToIntE

func ToIntE(i any) (int, error)

ToIntE casts an interface to an int type.

func ToIntSlice

func ToIntSlice(i any) []int

ToIntSlice casts an interface to a []int type.

func ToIntSliceE

func ToIntSliceE(i any) ([]int, error)

ToIntSliceE casts an interface to a []int type.

func ToSlice

func ToSlice(i any) []any

ToSlice casts an interface to a []any type.

func ToSliceE

func ToSliceE(i any) ([]any, error)

ToSliceE casts an interface to a []any type.

func ToString

func ToString(i any) string

ToString casts an interface to a string type.

func ToStringE

func ToStringE(i any) (string, error)

ToStringE casts an interface to a string type.

func ToStringMap

func ToStringMap(i any) map[string]any

ToStringMap casts an interface to a map[string]any type.

func ToStringMapBool

func ToStringMapBool(i any) map[string]bool

ToStringMapBool casts an interface to a map[string]bool type.

func ToStringMapBoolE

func ToStringMapBoolE(i any) (map[string]bool, error)

ToStringMapBoolE casts an interface to a map[string]bool type.

func ToStringMapE

func ToStringMapE(i any) (map[string]any, error)

ToStringMapE casts an interface to a map[string]any type.

func ToStringMapInt

func ToStringMapInt(i any) map[string]int

ToStringMapInt casts an interface to a map[string]int type.

func ToStringMapInt64

func ToStringMapInt64(i any) map[string]int64

ToStringMapInt64 casts an interface to a map[string]int64 type.

func ToStringMapInt64E

func ToStringMapInt64E(i any) (map[string]int64, error)

ToStringMapInt64E casts an interface to a map[string]int64{} type.

func ToStringMapIntE

func ToStringMapIntE(i any) (map[string]int, error)

ToStringMapIntE casts an interface to a map[string]int{} type.

func ToStringMapString

func ToStringMapString(i any) map[string]string

ToStringMapString casts an interface to a map[string]string type.

func ToStringMapStringE

func ToStringMapStringE(i any) (map[string]string, error)

ToStringMapStringE casts an interface to a map[string]string type.

func ToStringMapStringSlice

func ToStringMapStringSlice(i any) map[string][]string

ToStringMapStringSlice casts an interface to a map[string][]string type.

func ToStringMapStringSliceE

func ToStringMapStringSliceE(i any) (map[string][]string, error)

ToStringMapStringSliceE casts an interface to a map[string][]string type.

func ToStringSlice

func ToStringSlice(i any) []string

ToStringSlice casts an interface to a []string type.

func ToStringSliceE

func ToStringSliceE(i any) ([]string, error)

ToStringSliceE casts an interface to a []string type.

func ToTime

func ToTime(i any) time.Time

ToTime casts an interface to a time.Time type.

func ToTimeE

func ToTimeE(i any) (tim time.Time, err error)

ToTimeE casts an interface to a time.Time type.

func ToTimeInDefaultLocation

func ToTimeInDefaultLocation(i any, location *time.Location) time.Time

func ToTimeInDefaultLocationE

func ToTimeInDefaultLocationE(i any, location *time.Location) (tim time.Time, err error)

ToTimeInDefaultLocationE casts an empty interface to time.Time, interpreting inputs without a timezone to be in the given location, or the local timezone if nil.

func ToUint

func ToUint(i any) uint

ToUint casts an interface to a uint type.

func ToUint16

func ToUint16(i any) uint16

ToUint16 casts an interface to a uint16 type.

func ToUint16E

func ToUint16E(i any) (uint16, error)

ToUint16E casts an interface to a uint16 type.

func ToUint32

func ToUint32(i any) uint32

ToUint32 casts an interface to a uint32 type.

func ToUint32E

func ToUint32E(i any) (uint32, error)

ToUint32E casts an interface to a uint32 type.

func ToUint64

func ToUint64(i any) uint64

ToUint64 casts an interface to a uint64 type.

func ToUint64E

func ToUint64E(i any) (uint64, error)

ToUint64E casts an interface to a uint64 type.

func ToUint8

func ToUint8(i any) uint8

ToUint8 casts an interface to a uint8 type.

func ToUint8E

func ToUint8E(i any) (uint8, error)

ToUint8E casts an interface to a uint type.

func ToUintE

func ToUintE(i any) (uint, error)

ToUintE casts an interface to a uint type.

Types

This section is empty.

Jump to

Keyboard shortcuts

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