Skip to content

Latest commit

 

History

History
37 lines (31 loc) · 1.7 KB

README.md

File metadata and controls

37 lines (31 loc) · 1.7 KB

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