Documentation ¶
Overview ¶
Package gconv implements powerful and convenient converting functionality for any types of variables.
This package should keep much less dependencies with other packages.
Index ¶
- func Bool(i interface{}) bool
- func Byte(i interface{}) byte
- func Bytes(i interface{}) []byte
- func Convert(i interface{}, t string, params ...interface{}) interface{}
- func Duration(i interface{}) time.Duration
- func Float32(i interface{}) float32
- func Float32s(i interface{}) []float32
- func Float64(i interface{}) float64
- func Float64s(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 Int32s(i interface{}) []int32
- func Int64(i interface{}) int64
- func Int64s(i interface{}) []int64
- func Int8(i interface{}) int8
- func Interfaces(i interface{}) []interface{}
- func Ints(i interface{}) []int
- func Map(value interface{}, tags ...string) map[string]interface{}
- func MapDeep(value interface{}, tags ...string) map[string]interface{}
- func MapStrStr(value interface{}, tags ...string) map[string]string
- func MapStrStrDeep(value interface{}, tags ...string) map[string]string
- func MapToMap(params interface{}, pointer interface{}, mapping ...map[string]string) error
- func MapToMapDeep(params interface{}, pointer interface{}, mapping ...map[string]string) error
- func MapToMaps(params interface{}, pointer interface{}, mapping ...map[string]string) error
- func MapToMapsDeep(params interface{}, pointer interface{}, mapping ...map[string]string) error
- func Maps(value interface{}, tags ...string) []map[string]interface{}
- func MapsDeep(value interface{}, tags ...string) []map[string]interface{}
- func Rune(i interface{}) rune
- func Runes(i interface{}) []rune
- func Scan(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)
- func ScanDeep(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)
- func SliceAny(i interface{}) []interface{}
- func SliceFloat(i interface{}) []float64
- func SliceFloat32(i interface{}) []float32
- func SliceFloat64(i interface{}) []float64
- func SliceInt(i interface{}) []int
- func SliceInt32(i interface{}) []int32
- func SliceInt64(i interface{}) []int64
- func SliceMap(i interface{}) []map[string]interface{}
- func SliceMapDeep(i interface{}) []map[string]interface{}
- func SliceStr(i interface{}) []string
- func SliceStruct(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)
- func SliceStructDeep(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)
- func SliceUint(i interface{}) []uint
- func SliceUint32(i interface{}) []uint32
- func SliceUint64(i interface{}) []uint64
- func String(i interface{}) string
- func Strings(i interface{}) []string
- func Struct(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)
- func StructDeep(params interface{}, pointer interface{}, mapping ...map[string]string) error
- func Structs(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)
- func StructsDeep(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)
- func Time(i interface{}, format ...string) time.Time
- func Uint(i interface{}) uint
- func Uint16(i interface{}) uint16
- func Uint32(i interface{}) uint32
- func Uint32s(i interface{}) []uint32
- func Uint64(i interface{}) uint64
- func Uint64s(i interface{}) []uint64
- func Uint8(i interface{}) uint8
- func Uints(i interface{}) []uint
- func UnsafeBytesToStr(b []byte) string
- func UnsafeStrToBytes(s string) []byte
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
func Bool(i interface{}) bool
Bool converts <i> to bool. It returns false if <i> is: false, "", 0, "false", "off", "no", empty slice/map.
func Convert ¶
func Convert(i interface{}, t string, params ...interface{}) interface{}
Convert converts the variable <i> to the type <t>, the type <t> is specified by string. The optional parameter <params> is used for additional necessary parameter for this conversion. It supports common types conversion as its conversion based on type name string.
func Duration ¶
Duration converts <i> to time.Duration. If <i> is string, then it uses time.ParseDuration to convert it. If <i> is numeric, then it converts <i> as nanoseconds.
func GTime ¶
GTime converts <i> to *gtime.Time. The parameter <format> can be used to specify the format of <i>. If no <format> given, it converts <i> using gtime.NewFromTimeStamp if <i> is numeric, or using gtime.StrToTime if <i> is string.
func Interfaces ¶
func Interfaces(i interface{}) []interface{}
Interfaces converts <i> to []interface{}.
func Map ¶
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 ¶
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 ¶
MapStrStr converts <value> to map[string]string. Note that there might be data copy for this map type converting.
func MapStrStrDeep ¶
MapStrStrDeep converts <value> to map[string]string recursively. Note that there might be data copy for this map type converting.
func MapToMap ¶
MapToMap converts any map type variable <params> to another map type variable <pointer> using reflect. See doMapToMap.
func MapToMapDeep ¶
MapToMapDeep converts any map type variable <params> to another map type variable <pointer> using reflect recursively. See doMapToMap.
func MapToMaps ¶
MapToMaps converts any map type variable <params> to another map type variable <pointer>. See doMapToMaps.
func MapToMapsDeep ¶
MapToMapsDeep converts any map type variable <params> to another map type variable <pointer> recursively. See doMapToMaps.
func MapsDeep ¶
MapsDeep converts <i> to []map[string]interface{} recursively.
TODO completely implement the recursive converting for all types.
func Scan ¶
Scan automatically calls Struct or Structs function according to the type of parameter <pointer> to implement 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 ¶
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.
func SliceMapDeep ¶
func SliceMapDeep(i interface{}) []map[string]interface{}
SliceMapDeep is alias of MapsDeep.
func SliceStruct ¶
SliceStruct is alias of Structs.
func SliceStructDeep ¶
func SliceStructDeep(params interface{}, pointer interface{}, mapping ...map[string]string) (err error)
SliceStructDeep is alias of StructsDeep.
func String ¶
func String(i interface{}) string
String converts <i> to string. It's most common used converting function.
func Struct ¶
Struct maps the params key-value pairs to the corresponding struct object's attributes. The third parameter <mapping> is unnecessary, indicating the mapping rules between the custom key name and the attribute name(case sensitive).
Note:
- The <params> can be any type of map/struct, usually a map.
- The <pointer> should be type of *struct/**struct, which is a pointer to struct object or struct pointer.
- Only the public attributes of struct object can be mapped.
- If <params> is a map, the key of the map <params> can be lowercase. It will automatically convert the first letter of the key to uppercase in mapping procedure to do the matching. It ignores the map key, if it does not match.
func StructDeep ¶
StructDeep do Struct function recursively. See Struct.
func StructsDeep ¶
StructsDeep converts any slice to given struct slice recursively.
func UnsafeBytesToStr ¶
UnsafeBytesToStr converts []byte to string without memory copy. Note that, if you completely sure you will never use <b> variable in the feature, you can use this unsafe function to implement type conversion in high performance.
func UnsafeStrToBytes ¶
UnsafeStrToBytes converts string to []byte without memory copy. Note that, if you completely sure you will never use <s> variable in the feature, you can use this unsafe function to implement type conversion in high performance.
Types ¶
This section is empty.