Documentation ¶
Overview ¶
Package gconv implements powerful and easy-to-use converting functionality for any types of variables.
类型转换, 内部使用了bytes作为底层转换类型,效率很高。
Index ¶
- func Bool(i interface{}) bool
- func Bytes(i interface{}) []byte
- func Convert(i interface{}, t string, extraParams ...interface{}) interface{}
- func Float32(i interface{}) float32
- func Float64(i interface{}) float64
- func Floats(i interface{}) []float64
- func GTime(i interface{}, format ...string) *gtime.Time
- func Int(i interface{}) int
- func Int16(i interface{}) int16
- func Int32(i interface{}) int32
- func Int64(i interface{}) int64
- func Int8(i interface{}) int8
- func Interfaces(i interface{}) []interface{}
- func Ints(i interface{}) []int
- func Map(i interface{}, noTagCheck ...bool) map[string]interface{}
- func String(i interface{}) string
- func Strings(i interface{}) []string
- func Struct(params interface{}, objPointer interface{}, attrMapping ...map[string]string) error
- func Time(i interface{}, format ...string) time.Time
- func TimeDuration(i interface{}) time.Duration
- func Uint(i interface{}) uint
- func Uint16(i interface{}) uint16
- func Uint32(i interface{}) uint32
- func Uint64(i interface{}) uint64
- func Uint8(i interface{}) uint8
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
func Convert(i interface{}, t string, extraParams ...interface{}) interface{}
将变量i转换为字符串指定的类型t,非必须参数extraParams用以额外的参数传递
func Map ¶
任意类型转换为 map[string]interface{} 类型, 如果给定的输入参数i不是map类型,那么转换会失败,返回nil. 当i为struct对象时,第二个参数noTagCheck表示不检测json标签,否则将会使用json tag作为map的键名。
func Struct ¶
将params键值对参数映射到对应的struct对象属性上,第三个参数mapping为非必需,表示自定义名称与属性名称的映射关系。 需要注意: 1、第二个参数应当为struct对象指针; 2、struct对象的**公开属性(首字母大写)**才能被映射赋值; 3、map中的键名可以为小写,映射转换时会自动将键名首字母转为大写做匹配映射,如果无法匹配则忽略;
func TimeDuration ¶ added in v1.5.0
将变量i转换为time.Time类型
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.