dconv

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StructTagPriority = []string{"dconv", "param", "params", "c", "p", "json"}

Functions

func Bool

func Bool(any interface{}) bool

Bool 把任何类型转换成bool类型

func Byte

func Byte(any interface{}) byte

Byte converts `any` to byte.

func Bytes

func Bytes(any interface{}) []byte

Bytes converts `any` to []byte.

func Convert added in v0.0.3

func Convert(fromValue interface{}, toTypeName string, extraParams ...interface{}) interface{}

Convert converts the variable `fromValue` to the type `toTypeName`, the type `toTypeName` is specified by string. The optional parameter `extraParams` is used for additional necessary parameter for this conversion. It supports common types conversion as its conversion based on type name string.

func Duration added in v0.0.3

func Duration(any interface{}) time.Duration

Duration 把参数转换成Duration格式

func Float32

func Float32(i interface{}) float32

Float32 转换成float32

func Float32s added in v0.0.6

func Float32s(any interface{}) []float32

Float32s converts `i` to []float32.

func Float64

func Float64(i interface{}) float64

Float64 转换成float64

func Float64s added in v0.0.6

func Float64s(any interface{}) []float64

Float64s converts `i` to []float64.

func Floats added in v0.0.6

func Floats(any interface{}) []float64

Floats converts `i` to []float64.

func GTime added in v0.0.6

func GTime(any interface{}, format ...string) *dtime.Time

GTime 把任意类型any转换成 *dtime.Time

func Int

func Int(i interface{}) int

Int converts <i> to int.

func Int16

func Int16(i interface{}) int16

func Int32

func Int32(i interface{}) int32

Int32 converts <i> to int32.

func Int32s added in v0.0.6

func Int32s(any interface{}) []int32

Int32s 把any转换成 []int32

func Int64

func Int64(any interface{}) int64

Int64 converts `any` to int64.

func Int64s added in v0.0.6

func Int64s(any interface{}) []int64

Int64s 把any转换成 []int64

func Int8

func Int8(i interface{}) int8

Int8 converts <i> to int8.

func Interfaces

func Interfaces(i interface{}) []interface{}

func Ints added in v0.0.6

func Ints(any interface{}) []int

Ints 把any转换成 []int

func Map

func Map(value interface{}, tags ...string) map[string]interface{}

Map converts any variable `value` to map[string]interface{}. If the parameter `value` is not a map/struct/*struct type, then the conversion will fail and returns nil.

If `value` is a struct/*struct object, the second parameter `tags` specifies the most priority tags that will be detected, otherwise it detects the tags in order of: gconv, json, field name.

func MapDeep

func MapDeep(value interface{}, tags ...string) map[string]interface{}

MapDeep does Map function recursively, which means if the attribute of `value` is also a struct/*struct, calls Map function on this attribute converting it to a map[string]interface{} type variable. Also see Map.

func MapStrStr

func MapStrStr(value interface{}, tags ...string) map[string]string

MapStrStr converts `value` to map[string]string. Note that there might be data copy for this map type converting.

func MapStrStrDeep

func MapStrStrDeep(value interface{}, tags ...string) map[string]string

MapStrStrDeep converts `value` to map[string]string recursively. Note that there might be data copy for this map type converting.

func MapToMap added in v0.0.9

func MapToMap(params interface{}, pointer interface{}, mapping ...map[string]string) error

MapToMap converts any map type variable `params` to another map type variable `pointer` using reflect. See doMapToMap.

func MapToMaps added in v0.0.9

func MapToMaps(params interface{}, pointer interface{}, mapping ...map[string]string) error

MapToMaps converts any slice type variable `params` to another map slice type variable `pointer`. See doMapToMaps.

func MapToMapsDeep added in v0.0.9

func MapToMapsDeep(params interface{}, pointer interface{}, mapping ...map[string]string) error

MapToMapsDeep converts any slice type variable `params` to another map slice type variable `pointer` recursively. Deprecated, use MapToMaps instead.

func Maps added in v0.0.6

func Maps(value interface{}, tags ...string) []map[string]interface{}

Maps converts `value` to []map[string]interface{}. Note that it automatically checks and converts json string to []map if `value` is string/[]byte.

func MapsDeep added in v0.0.6

func MapsDeep(value interface{}, tags ...string) []map[string]interface{}

MapsDeep converts `value` to []map[string]interface{} recursively.

TODO completely implement the recursive converting for all types.

func Rune

func Rune(i interface{}) rune

Rune rune 类型,代表一个 UTF-8 字符,把其他类型转换成rune

func Runes

func Runes(i interface{}) []rune

Runes converts <i> to []rune.

func Scan added in v0.0.9

func Scan(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)

Scan automatically calls MapToMap, MapToMaps, Struct or Structs function according to the type of parameter `pointer` to implement the converting. It calls function MapToMap if `pointer` is type of *map to do the converting. It calls function MapToMaps if `pointer` is type of *[]map/*[]*map to do the converting. It calls function Struct if `pointer` is type of *struct/**struct to do the converting. It calls function Structs if `pointer` is type of *[]struct/*[]*struct to do the converting.

func ScanDeep added in v0.0.9

func ScanDeep(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)

ScanDeep automatically calls StructDeep or StructsDeep function according to the type of parameter `pointer` to implement the converting.. It calls function StructDeep if `pointer` is type of *struct/**struct to do the converting. It calls function StructsDeep if `pointer` is type of *[]struct/*[]*struct to do the converting. Deprecated, use Scan instead.

func SliceAny

func SliceAny(i interface{}) []interface{}

SliceAny 把任何对象转换成切片

func SliceFloat added in v0.0.6

func SliceFloat(any interface{}) []float64

SliceFloat is alias of Floats.

func SliceFloat32 added in v0.0.6

func SliceFloat32(any interface{}) []float32

SliceFloat32 is alias of Float32s.

func SliceFloat64 added in v0.0.6

func SliceFloat64(any interface{}) []float64

SliceFloat64 is alias of Float64s.

func SliceInt added in v0.0.6

func SliceInt(any interface{}) []int

SliceInt Ints的别名

func SliceInt32 added in v0.0.6

func SliceInt32(any interface{}) []int32

SliceInt32 Int32s的别名

func SliceInt64 added in v0.0.6

func SliceInt64(any interface{}) []int64

SliceInt64 Int64s的别名

func SliceMap added in v0.0.6

func SliceMap(any interface{}) []map[string]interface{}

SliceMap is alias of Maps.

func SliceMapDeep added in v0.0.6

func SliceMapDeep(any interface{}) []map[string]interface{}

SliceMapDeep is alias of MapsDeep.

func SliceStr

func SliceStr(i interface{}) []string

SliceStr Strings的别名

func SliceStruct added in v0.0.6

func SliceStruct(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)

SliceStruct is alias of Structs.

func SliceUint added in v0.0.6

func SliceUint(any interface{}) []uint

SliceUint is alias of Uints.

func SliceUint32 added in v0.0.6

func SliceUint32(any interface{}) []uint32

SliceUint32 is alias of Uint32s.

func SliceUint64 added in v0.0.6

func SliceUint64(any interface{}) []uint64

SliceUint64 is alias of Uint64s.

func String

func String(any interface{}) string

String 把 i 转换成string类型

func Strings

func Strings(i interface{}) []string

Strings 把<i>这个interface转换成 []string

func Struct added in v0.0.3

func Struct(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)

Struct 将参数params 的key-value字典对象映射成pointer指向的struct的对象属性。 mapping参数不是必须的,它的作用是映射转换的key名

func StructDeep added in v0.0.6

func StructDeep(params interface{}, pointer interface{}, mapping ...map[string]string) error

func StructTag added in v0.0.6

func StructTag(params interface{}, pointer interface{}, priorityTag string) (err error)

func Structs added in v0.0.6

func Structs(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)

Structs converts any slice to given struct slice.

func StructsDeep added in v0.0.6

func StructsDeep(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)

StructsDeep converts any slice to given struct slice recursively. Deprecated, use Structs instead.

func StructsTag added in v0.0.6

func StructsTag(params interface{}, pointer interface{}, priorityTag string) (err error)

StructsTag acts as Structs but also with support for priority tag feature, which retrieves the specified tags for `params` key-value items to struct attribute names mapping. The parameter `priorityTag` supports multiple tags that can be joined with char ','.

func Time added in v0.0.6

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

Time 把任意类型any转换成 time.Time.

func Uint

func Uint(i interface{}) uint

Uint converts <i> to uint.

func Uint16

func Uint16(i interface{}) uint16

Uint16 converts <i> to uint16.

func Uint32

func Uint32(i interface{}) uint32

Uint32 converts <i> to uint32.

func Uint32s added in v0.0.6

func Uint32s(any interface{}) []uint32

Uint32s converts `i` to []uint32.

func Uint64

func Uint64(i interface{}) uint64

func Uint64s added in v0.0.6

func Uint64s(any interface{}) []uint64

Uint64s converts `i` to []uint64.

func Uint8

func Uint8(i interface{}) uint8

Uint8 converts <i> to uint8.

func Uints added in v0.0.6

func Uints(any interface{}) []uint

Uints converts `i` to []uint.

func UnsafeBytesToStr

func UnsafeBytesToStr(b []byte) string

func UnsafeStrToBytes

func UnsafeStrToBytes(s string) []byte

Types

This section is empty.

Jump to

Keyboard shortcuts

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