Skip to content
/ go-cast Public

Supply some functions to convert the data between types, such as ToXXX and MustToXXX.

License

Notifications You must be signed in to change notification settings

xgfone/go-cast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a2a8b30 · May 12, 2024

History

33 Commits
May 12, 2024
Mar 30, 2023
May 12, 2020
May 12, 2024
May 12, 2024
May 12, 2024
Mar 30, 2023
Jul 12, 2023
Mar 30, 2023
May 12, 2024
May 12, 2024
Apr 2, 2023
May 12, 2024

Repository files navigation

Go Type Cast Build Status GoDoc License

Provide some functions, supporting Go1.21+, to convert the value between different types, such as ToXXX.

Installation

$ go get -u github.com/xgfone/go-cast

API

Convert Function

func ToTime(any interface{}) (dst time.Time, err error)
func ToBool(any interface{}) (dst bool, err error)
func ToInt64(any interface{}) (dst int64, err error)
func ToUint64(any interface{}) (dst uint64, err error)
func ToFloat64(any interface{}) (dst float64, err error)
func ToString(any interface{}) (dst string, err error)
func ToDuration(any interface{}) (dst time.Duration, err error)

func ToTimeInLocation(any interface{}, loc *time.Location, layouts ...string) (time.Time, error)
func MustToTimeInLocation(any interface{}, loc *time.Location, layouts ...string) time.Time
func MustParseTime(value string, loc *time.Location, layouts ...string) time.Time
func TryParseTime(value string, loc *time.Location, layouts ...string) (time.Time, error)
func Set(dst, src interface{}) (err error)

// Must is the generic function and used by associating with ToXXX. For example,
//   Must(ToBool(any))
//   Must(ToInt64(any))
//   Must(ToUint64(any))
//   Must(ToFloat64(any))
//   Must(ToString(any))
//   Must(ToDuration(any))
//   Must(ToTime(any))
func Must[T any](value T, err error) T

About

Supply some functions to convert the data between types, such as ToXXX and MustToXXX.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages