cast

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

README

cast

提供了很多类型之间相互转换的函数。

Install

go get github.com/go-spring/spring-base@v1.1.0-rc2 

Import

import "github.com/go-spring/spring-base/cast"

Example

fmt.Println(cast.ToInt(10))   // 10
fmt.Println(cast.ToInt(10.0)) // 10
fmt.Println(cast.ToInt("10")) // 10
fmt.Println(cast.ToInt(true)) // 1

Documentation

Index

Constants

View Source
const (
	Nanosecond  = "ns" // 纳秒
	Microsecond = "μs" // 微秒
	Millisecond = "ms" // 毫秒
	Second      = "s"  // 秒
	Minute      = "m"  // 分
	Hour        = "h"  // 小时
)

Variables

This section is empty.

Functions

func FlatJSON

func FlatJSON(data interface{}) map[string]string

func HexDigitToInt

func HexDigitToInt(c byte) int

func IsHexDigit

func IsHexDigit(c byte) bool

func ToBool

func ToBool(i interface{}) bool

ToBool casts an interface{} to a bool. 在类型明确的情况下推荐使用标准库函数。

func ToBoolE

func ToBoolE(i interface{}) (bool, error)

ToBoolE casts an interface{} to a bool. 在类型明确的情况下推荐使用标准库函数。

func ToDuration

func ToDuration(i interface{}, unit ...string) time.Duration

ToDuration casts an interface{} to a time.Duration.

func ToDurationE

func ToDurationE(i interface{}, unit ...string) (time.Duration, error)

ToDurationE casts an interface{} to a time.Duration.

func ToFloat32

func ToFloat32(i interface{}) float32

ToFloat32 casts an interface{} to a float32. 在类型明确的情况下推荐使用标准库函数。

func ToFloat64

func ToFloat64(i interface{}) float64

ToFloat64 casts an interface{} to a float64. 在类型明确的情况下推荐使用标准库函数。

func ToFloat64E

func ToFloat64E(i interface{}) (float64, error)

ToFloat64E casts an interface{} to a float64. 在类型明确的情况下推荐使用标准库函数。

func ToInt

func ToInt(i interface{}) int

ToInt casts an interface{} to an int. 在类型明确的情况下推荐使用标准库函数。

func ToInt16

func ToInt16(i interface{}) int16

ToInt16 casts an interface{} to an int16. 在类型明确的情况下推荐使用标准库函数。

func ToInt32

func ToInt32(i interface{}) int32

ToInt32 casts an interface{} to an int32. 在类型明确的情况下推荐使用标准库函数。

func ToInt64

func ToInt64(i interface{}) int64

ToInt64 casts an interface{} to an int64. 在类型明确的情况下推荐使用标准库函数。

func ToInt64E

func ToInt64E(i interface{}) (int64, error)

ToInt64E casts an interface{} to an int64. 在类型明确的情况下推荐使用标准库函数。

func ToInt8

func ToInt8(i interface{}) int8

ToInt8 casts an interface{} to an int8. 在类型明确的情况下推荐使用标准库函数。

func ToString

func ToString(i interface{}) string

ToString casts an interface{} to a string. 在类型明确的情况下推荐使用标准库函数。

func ToStringE

func ToStringE(i interface{}) (string, error)

ToStringE casts an interface{} to a string. 在类型明确的情况下推荐使用标准库函数。

func ToStringMap

func ToStringMap(i interface{}) map[string]interface{}

ToStringMap casts an interface{} to a map[string]interface{}.

func ToStringMapE

func ToStringMapE(i interface{}) (map[string]interface{}, error)

ToStringMapE casts an interface{} to a map[string]interface{}.

func ToStringMapString

func ToStringMapString(i interface{}) map[string]string

ToStringMapString casts an interface{} to a map[string]string.

func ToStringMapStringE

func ToStringMapStringE(i interface{}) (map[string]string, error)

ToStringMapStringE casts an interface{} to a map[string]string.

func ToStringSlice

func ToStringSlice(i interface{}) []string

ToStringSlice casts an interface{} to a []string.

func ToStringSliceE

func ToStringSliceE(i interface{}) ([]string, error)

ToStringSliceE casts an interface{} to a []string.

func ToTime

func ToTime(i interface{}, arg ...string) time.Time

ToTime casts an interface{} to a time.Time.

func ToTimeE

func ToTimeE(i interface{}, arg ...string) (time.Time, error)

ToTimeE casts an interface{} to a time.Time.

func ToUint

func ToUint(i interface{}) uint

ToUint casts an interface{} to an uint. 在类型明确的情况下推荐使用标准库函数。

func ToUint16

func ToUint16(i interface{}) uint16

ToUint16 casts an interface{} to an uint16. 在类型明确的情况下推荐使用标准库函数。

func ToUint32

func ToUint32(i interface{}) uint32

ToUint32 casts an interface{} to an uint32. 在类型明确的情况下推荐使用标准库函数。

func ToUint64

func ToUint64(i interface{}) uint64

ToUint64 casts an interface{} to an uint64. 在类型明确的情况下推荐使用标准库函数。

func ToUint64E

func ToUint64E(i interface{}) (uint64, error)

ToUint64E casts an interface{} to an uint64. 在类型明确的情况下推荐使用标准库函数。

func ToUint8

func ToUint8(i interface{}) uint8

ToUint8 casts an interface{} to an uint8. 在类型明确的情况下推荐使用标准库函数。

Types

This section is empty.

Jump to

Keyboard shortcuts

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