Documentation ¶
Overview ¶
Package gconv implements powerful and easy-to-use converting functionality for any types of variables.
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 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(value interface{}, tags ...string) map[string]interface{}
- func MapDeep(value interface{}, tags ...string) map[string]interface{}
- func Maps(i interface{}) []map[string]interface{}
- func Rune(i interface{}) rune
- func Runes(i interface{}) []rune
- func String(i interface{}) string
- func Strings(i interface{}) []string
- func Struct(params interface{}, pointer interface{}, mapping ...map[string]string) error
- func StructDeep(params interface{}, pointer interface{}, mapping ...map[string]string) 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 Uint64(i interface{}) uint64
- func Uint8(i interface{}) uint8
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", 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 unnecessary parameter <params> is used for additional parameter passing.
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 type, then the conversion will fail and returns nil. If <value> is a 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.
func Maps ¶
func Maps(i interface{}) []map[string]interface{}
Maps converts <i> to []map[string]interface{}.
func Struct ¶
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:
- The <params> can be any type of map/struct, usually a map.
- The second parameter <pointer> should be a pointer to the struct object.
- 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.
Types ¶
This section is empty.