convert

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package convert 类型转化

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(i interface{}, t string) interface{}

Convert 将变量i转换为字符串指定的类型t t: int,int8...[]byte,time.Time,time.Duration等

func IPToUint

func IPToUint(ipstr string) (uip uint32)

IPToUint 字符串转为整形

func MapToStruct

func MapToStruct(m map[string]interface{}, o interface{}) error

MapToStruct 将map键值对映射到对应的struct对象属性上,需要注意: 1、第二个参数为struct对象指针; 2、struct对象的公开属性才能被映射赋值; 3、map中的键名可以为小写,映射转换时会自动将键名首字母转为大写做匹配映射,如果无法匹配则忽略;

func Round

func Round(x float64, prec int) float64

Round 四舍五入 prec 精度

func RoundInt

func RoundInt(x float64, prec int) int

RoundInt 四舍五入到整数 prec 精度,根据精度位数转到相应整数

func ToBool

func ToBool(i interface{}) bool

ToBool false: "", 0, false, off

func ToBytes

func ToBytes(i interface{}) []byte

ToBytes 转化为[]byte

func ToFloat32

func ToFloat32(i interface{}) float32

ToFloat32 转化为float32

func ToFloat64

func ToFloat64(i interface{}) float64

ToFloat64 转化为float64

func ToInt

func ToInt(i interface{}) int

ToInt 转化为int

func ToInt8

func ToInt8(i interface{}) int8

ToInt8 转化为int8

func ToInt16

func ToInt16(i interface{}) int16

ToInt16 转化为int16

func ToInt32

func ToInt32(i interface{}) int32

ToInt32 转化int32

func ToInt64

func ToInt64(i interface{}) int64

ToInt64 转化为int64

func ToString

func ToString(i interface{}) string

ToString 基础的字符串类型转换

func ToStringSlice

func ToStringSlice(i interface{}) []string

ToStringSlice 转化为字符串切片

func ToTime

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

ToTime 转化为time.Time

func ToTimeDuration

func ToTimeDuration(i interface{}) time.Duration

ToTimeDuration 将变量i转换为time.Duration类型

func ToUint

func ToUint(i interface{}) uint

ToUint 转化为unit

func ToUint8

func ToUint8(i interface{}) uint8

ToUint8 转化为uint8

func ToUint16

func ToUint16(i interface{}) uint16

ToUint16 转化为uint16

func ToUint32

func ToUint32(i interface{}) uint32

ToUint32 转化为uint32

func ToUint64

func ToUint64(i interface{}) uint64

ToUint64 转化为uint64

func UintToIP

func UintToIP(uip uint32) string

UintToIP 整形转为字符串

Types

This section is empty.

Jump to

Keyboard shortcuts

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