gf: github.com/gogf/gf/g/util/gconv Index | Files

package gconv

import "github.com/gogf/gf/g/util/gconv"

Package gconv implements powerful and easy-to-use converting functionality for any types of variables.

Index

Package Files

gconv.go gconv_map.go gconv_slice.go gconv_struct.go gconv_time.go

func Bool Uses

func Bool(i interface{}) bool

Bool converts <i> to bool. It returns false if <i> is: false, "", 0, "false", "off", empty slice/map.

func Byte Uses

func Byte(i interface{}) byte

Byte converts <i> to byte.

func Bytes Uses

func Bytes(i interface{}) []byte

Bytes converts <i> to []byte.

func Convert Uses

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 unnecessary parameter <params> is used for additional parameter passing.

func Duration Uses

func Duration(i interface{}) time.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 Float32 Uses

func Float32(i interface{}) float32

Float32 converts <i> to float32.

func Float64 Uses

func Float64(i interface{}) float64

Float64 converts <i> to float64.

func Floats Uses

func Floats(i interface{}) []float64

Strings converts <i> to []float64.

func GTime Uses

func GTime(i interface{}, format ...string) *gtime.Time

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 Int Uses

func Int(i interface{}) int

Int converts <i> to int.

func Int16 Uses

func Int16(i interface{}) int16

Int16 converts <i> to int16.

func Int32 Uses

func Int32(i interface{}) int32

Int32 converts <i> to int32.

func Int64 Uses

func Int64(i interface{}) int64

Int64 converts <i> to int64.

func Int8 Uses

func Int8(i interface{}) int8

Int8 converts <i> to int8.

func Interfaces Uses

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

Interfaces converts <i> to []interface{}.

func Ints Uses

func Ints(i interface{}) []int

Ints converts <i> to []int.

func Map Uses

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, and then the field name.

func MapDeep Uses

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

MapDeep do Map function recursively. See Map.

func Maps Uses

func Maps(i interface{}) []map[string]interface{}

Maps converts <i> to []map[string]interface{}.

func MapsDeep Uses

func MapsDeep(i interface{}) []map[string]interface{}

MapsDeep converts <i> to []map[string]interface{} recursively.

func Rune Uses

func Rune(i interface{}) rune

Rune converts <i> to rune.

func Runes Uses

func Runes(i interface{}) []rune

Runes converts <i> to []rune.

func SliceAny Uses

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

SliceAny is alias of Interfaces.

func SliceFloat Uses

func SliceFloat(i interface{}) []float64

SliceFloat is alias of Floats.

func SliceInt Uses

func SliceInt(i interface{}) []int

SliceInt is alias of Ints.

func SliceMap Uses

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

SliceMap is alias of Maps.

func SliceMapDeep Uses

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

SliceMapDeep is alias of MapsDeep.

func SliceStr Uses

func SliceStr(i interface{}) []string

SliceStr is alias of Strings.

func SliceStruct Uses

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

SliceStruct is alias of Structs.

func SliceStructDeep Uses

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

SliceStructDeep is alias of StructsDeep.

func String Uses

func String(i interface{}) string

String converts <i> to string.

func Strings Uses

func Strings(i interface{}) []string

Strings converts <i> to []string.

func Struct Uses

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

Struct maps the params key-value pairs to the corresponding struct object's properties. The third parameter <mapping> is unnecessary, indicating the mapping rules between the custom key name and the attribute name(case sensitive).

Note: 1. The <params> can be any type of map/struct, usually a map. 2. The second parameter <pointer> should be a pointer to the struct object. 3. Only the public attributes of struct object can be mapped. 4. 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 Uses

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

StructDeep do Struct function recursively. See Struct.

func Structs Uses

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

Structs converts any slice to given struct slice.

func StructsDeep Uses

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

StructsDeep converts any slice to given struct slice recursively.

func Time Uses

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

Time converts <i> to time.Time.

func Uint Uses

func Uint(i interface{}) uint

Uint converts <i> to uint.

func Uint16 Uses

func Uint16(i interface{}) uint16

Uint16 converts <i> to uint16.

func Uint32 Uses

func Uint32(i interface{}) uint32

Uint32 converts <i> to uint32.

func Uint64 Uses

func Uint64(i interface{}) uint64

Uint64 converts <i> to uint64.

func Uint8 Uses

func Uint8(i interface{}) uint8

Uint8 converts <i> to uint8.

Package gconv imports 12 packages (graph) and is imported by 52 packages. Updated 2019-07-19. Refresh now. Tools for package owners.