cast

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDatetimeFormat = strset.New(
	"20060102150405",
	"20060102",
)

Functions

func CastSlice

func CastSlice[From, To any](i []From) (ret []To)

Slice casts an []From to a []To type.

func CastSliceE

func CastSliceE[From, To any](i []From) (ret []To, err error)

Slice casts an []From to a []To type.

func TimeAssume

func TimeAssume[I int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64](v I) (t time.Time, err error)

默认时间范围 北京时间 1973-03-03 17:46:40 ~ 2255-03-15 00:00:00

func TimeAssumes

func TimeAssumes[I int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64](vs []I) (ts []time.Time, err error)

func To added in v0.8.2

func To[V any](i any) V

func ToBool

func ToBool(i any) bool

ToBool casts an interface to a bool type.

func ToBoolE

func ToBoolE(i any) (bool, error)

ToBool 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)

ToBoolSlice casts an interface to a []bool type.

func ToDateTimes

func ToDateTimes(v any) (ts []time.Time, err error)

func ToDatetime

func ToDatetime(v any, layouts ...string) time.Time

当 v 为数值时,根据数值范围确定时间精度为纳秒、微秒、毫秒、秒值,只能返回 北京时间 1973-03-03 17:46:40 ~ 2255-03-15 00:00:00 当 v 为字符串时,可解析多种默认格式,可通过 layouts 指定更多的时间格式 v 为数值时,可通过 layouts 明确指定数值精度为纳秒 ns、微秒 us、毫秒 ms、秒 s、分 m、时 h、天 d

func ToDatetimeE

func ToDatetimeE(v any, layouts ...string) (time.Time, error)

func ToDuration

func ToDuration(i any) time.Duration

ToDuration casts an interface to a time.Duration type.

func ToDurationE

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

ToDuration 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)

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

func ToE added in v0.8.2

func ToE[V any](i any) (V, error)

func ToFloat32

func ToFloat32(i any) float32

ToFloat32 casts an interface to a float32 type.

func ToFloat32E

func ToFloat32E(i any) (float32, error)

ToFloat32 casts an interface to a float32 type.

func ToFloat32Slice

func ToFloat32Slice(i any) []float32

ToIntSlice casts an interface to a []float32 type.

func ToFloat32SliceE

func ToFloat32SliceE(i any) ([]float32, error)

ToIntSlice casts an interface to a []float32 type.

func ToFloat64

func ToFloat64(i any) float64

func ToFloat64E

func ToFloat64E(i any) (float64, error)

func ToFloat64Slice

func ToFloat64Slice(i any) []float64

ToIntSlice casts an interface to a []float64 type.

func ToFloat64SliceE

func ToFloat64SliceE(i any) ([]float64, error)

ToIntSlice casts an interface to a []float64 type.

func ToInt

func ToInt(i any) int

func ToInt8

func ToInt8(i any) int8

ToInt8 casts an interface to an int8 type.

func ToInt8E

func ToInt8E(i any) (int8, error)

ToInt8 casts an interface to an int8 type.

func ToInt16

func ToInt16(i any) int16

ToInt16 casts an interface to an int16 type.

func ToInt16E

func ToInt16E(i any) (int16, error)

ToInt16 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)

ToInt32 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)

ToInt64 casts an interface to an int64 type.

func ToInt64Slice

func ToInt64Slice(i any) []int64

ToIntSlice casts an interface to a []int64 type.

func ToInt64SliceE

func ToInt64SliceE(i any) ([]int64, error)

ToIntSlice casts an interface to a []int64 type.

func ToIntE

func ToIntE(i any) (int, error)

func ToIntSlice

func ToIntSlice(i any) []int

ToIntSlice casts an interface to a []int type.

func ToIntSliceE

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

ToIntSlice casts an interface to a []int type.

func ToList added in v0.8.2

func ToList[V any](i any) []V

ToList casts an interface to a []any type.

func ToListE added in v0.8.2

func ToListE[V any](i any) ([]V, error)

ToList casts an interface to a []any type.

func ToMap added in v0.8.2

func ToMap[K comparable, V any](i any) map[K]V

ToMap casts an interface to a map[any]any type.

func ToMapE added in v0.8.2

func ToMapE[K comparable, V any](i any) (map[K]V, error)

func ToSlice

func ToSlice(i any) []any

ToSlice casts an interface to a []any type.

func ToSliceE

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

ToSlice casts an interface to a []any type.

func ToStr

func ToStr(v any) (rets string)

func ToString

func ToString(i any) string

ToString casts an interface to a string type.

func ToStringE

func ToStringE(i any) (string, error)

ToString 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)

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

func ToStringMapE

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

ToStringMap 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)

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

func ToStringMapIntE

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

ToStringMapInt 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)

ToStringMapString 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)

ToStringMapStringSlice 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)

ToStringSlice casts an interface to a []string type.

func ToStrs

func ToStrs(v any) (rets []string)

func ToTime

func ToTime(i any) time.Time

ToTime casts an interface to a time.Time type. ToTimeInDefaultLocation

func ToTimeE

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

ToTime 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) (time.Time, error)

func ToUint

func ToUint(i any) uint

ToUint casts an interface to a uint type.

func ToUint8

func ToUint8(i any) uint8

ToUint8 casts an interface to a uint8 type.

func ToUint8E

func ToUint8E(i any) (uint8, error)

ToUint8 casts an interface to a uint8 type.

func ToUint16

func ToUint16(i any) uint16

ToUint16 casts an interface to a uint16 type.

func ToUint16E

func ToUint16E(i any) (uint16, error)

ToUint16 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)

ToUint32 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)

ToUint64 casts an interface to a uint64 type.

func ToUintE

func ToUintE(i any) (uint, error)

ToUint casts an interface to a uint type.

func ToUnixNano

func ToUnixNano(ctime int64) (int64, error)

默认时间范围 北京时间 1973-03-03 17:46:40 ~ 2255-03-15 00:00:00

func ToUnixNanos

func ToUnixNanos(v any) (ts []int64, err error)

func UnmarshalJsonString

func UnmarshalJsonString(encodedstring string) string

func Unquote

func Unquote(ss string) string

Types

This section is empty.

Directories

Path Synopsis
Package dateparse parses date-strings without knowing the format in advance, using a fast lex based approach to eliminate shotgun attempts.
Package dateparse parses date-strings without knowing the format in advance, using a fast lex based approach to eliminate shotgun attempts.

Jump to

Keyboard shortcuts

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