Documentation ¶
Index ¶
- func Convert(fromValue interface{}, toTypeName string, extraParams ...interface{}) interface{}
- 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 Struct[T any](params interface{}, pointer T, mapping ...map[string]string) (res T)
- func StructTag[T any](params interface{}, pointer T, priorityTag string) (res T)
- func StructTagWithError[T any](params interface{}, pointer T, priorityTag string) (res T, err error)
- func StructWithError[T any](params interface{}, pointer T, mapping ...map[string]string) (res T, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
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 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 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 StructTag ¶
StructTag acts as Struct 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 StructTagWithError ¶
Types ¶
This section is empty.