cast

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

cast

Provides many conversion functions between types.

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

Overview

Package cast provides many conversion functions between types.

Index

Constants

This section is empty.

Variables

View Source
var (
	FAST = &fastEncoding{}
	JSON = &jsonEncoding{}
)

Functions

func BoolPtr added in v1.1.3

func BoolPtr(s bool) *bool

func BytesToString added in v1.1.3

func BytesToString(b []byte) string

BytesToString converts byte slice to string without memory allocation.

func Float32Ptr added in v1.1.3

func Float32Ptr(s float32) *float32

func Float64Ptr added in v1.1.3

func Float64Ptr(s float64) *float64

func HexDigitToInt

func HexDigitToInt(c byte) int

HexDigitToInt converts a hex digit into an int.

func Int16Ptr added in v1.1.3

func Int16Ptr(s int16) *int16

func Int32Ptr added in v1.1.3

func Int32Ptr(s int32) *int32

func Int64Ptr added in v1.1.3

func Int64Ptr(s int64) *int64

func Int8Ptr added in v1.1.3

func Int8Ptr(s int8) *int8

func IntPtr added in v1.1.3

func IntPtr(s int) *int

func IsHexDigit

func IsHexDigit(c byte) bool

IsHexDigit returns whether the character is a valid hexadecimal character.

func StringPtr added in v1.1.3

func StringPtr(s string) *string

func StringToBytes added in v1.1.3

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice without memory allocation.

func ToBool

func ToBool(i interface{}) bool

ToBool casts an interface{} to a bool. When type is clear, it is recommended to use standard library functions.

func ToBoolE

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

ToBoolE casts an interface{} to a bool. When type is clear, it is recommended to use standard library functions.

func ToDuration

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

ToDuration casts an interface{} to a time.Duration. When type is clear, it is recommended to use standard library functions.

func ToDurationE

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

ToDurationE casts an interface{} to a time.Duration. When type is clear, it is recommended to use standard library functions.

func ToFloat32

func ToFloat32(i interface{}) float32

ToFloat32 casts an interface{} to a float32. When type is clear, it is recommended to use standard library functions.

func ToFloat64

func ToFloat64(i interface{}) float64

ToFloat64 casts an interface{} to a float64. When type is clear, it is recommended to use standard library functions.

func ToFloat64E

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

ToFloat64E casts an interface{} to a float64. When type is clear, it is recommended to use standard library functions.

func ToInt

func ToInt(i interface{}) int

ToInt casts an interface{} to an int. When type is clear, it is recommended to use standard library functions.

func ToInt16

func ToInt16(i interface{}) int16

ToInt16 casts an interface{} to an int16. When type is clear, it is recommended to use standard library functions.

func ToInt32

func ToInt32(i interface{}) int32

ToInt32 casts an interface{} to an int32. When type is clear, it is recommended to use standard library functions.

func ToInt64

func ToInt64(i interface{}) int64

ToInt64 casts an interface{} to an int64. When type is clear, it is recommended to use standard library functions.

func ToInt64E

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

ToInt64E casts an interface{} to an int64. When type is clear, it is recommended to use standard library functions.

func ToInt8

func ToInt8(i interface{}) int8

ToInt8 casts an interface{} to an int8. When type is clear, it is recommended to use standard library functions.

func ToString

func ToString(i interface{}) string

ToString casts an interface{} to a string. When type is clear, it is recommended to use standard library functions.

func ToStringE

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

ToStringE casts an interface{} to a string. When type is clear, it is recommended to use standard library functions.

func ToTime

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

ToTime casts an interface{} to a time.Time. When type is clear, it is recommended to use standard library functions.

func ToTimeE

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

ToTimeE casts an interface{} to a time.Time. When type is clear, it is recommended to use standard library functions.

func ToUint

func ToUint(i interface{}) uint

ToUint casts an interface{} to an uint. When type is clear, it is recommended to use standard library functions.

func ToUint16

func ToUint16(i interface{}) uint16

ToUint16 casts an interface{} to an uint16. When type is clear, it is recommended to use standard library functions.

func ToUint32

func ToUint32(i interface{}) uint32

ToUint32 casts an interface{} to an uint32. When type is clear, it is recommended to use standard library functions.

func ToUint64

func ToUint64(i interface{}) uint64

ToUint64 casts an interface{} to an uint64. When type is clear, it is recommended to use standard library functions.

func ToUint64E

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

ToUint64E casts an interface{} to an uint64. When type is clear, it is recommended to use standard library functions.

func ToUint8

func ToUint8(i interface{}) uint8

ToUint8 casts an interface{} to an uint8. When type is clear, it is recommended to use standard library functions.

func Uint16Ptr added in v1.1.3

func Uint16Ptr(s uint16) *uint16

func Uint32Ptr added in v1.1.3

func Uint32Ptr(s uint32) *uint32

func Uint64Ptr added in v1.1.3

func Uint64Ptr(s uint64) *uint64

func Uint8Ptr added in v1.1.3

func Uint8Ptr(s uint8) *uint8

func UintPtr added in v1.1.3

func UintPtr(s uint) *uint

Types

type ConversionArg added in v1.1.3

type ConversionArg struct {
	DeepCopy bool
}

Jump to

Keyboard shortcuts

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