2020-05-04 23:42:51 +08:00
|
|
|
// Copyright 2020 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
|
|
package gvar
|
|
|
|
|
|
|
|
import "github.com/gogf/gf/util/gconv"
|
|
|
|
|
|
|
|
// Map converts and returns <v> as map[string]interface{}.
|
2020-06-16 17:38:05 +08:00
|
|
|
func (v *VarImp) Map(tags ...string) map[string]interface{} {
|
2020-05-04 23:42:51 +08:00
|
|
|
return gconv.Map(v.Val(), tags...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MapStrStr converts and returns <v> as map[string]string.
|
2020-06-16 17:38:05 +08:00
|
|
|
func (v *VarImp) MapStrStr(tags ...string) map[string]string {
|
2020-05-04 23:42:51 +08:00
|
|
|
return gconv.MapStrStr(v.Val(), tags...)
|
|
|
|
}
|
|
|
|
|
2020-06-16 17:38:05 +08:00
|
|
|
// MapStrVar converts and returns <v> as map[string]Var.
|
|
|
|
func (v *VarImp) MapStrVar(tags ...string) map[string]Var {
|
2020-05-04 23:42:51 +08:00
|
|
|
m := v.Map(tags...)
|
|
|
|
if len(m) > 0 {
|
2020-06-16 17:38:05 +08:00
|
|
|
vMap := make(map[string]Var, len(m))
|
2020-05-04 23:42:51 +08:00
|
|
|
for k, v := range m {
|
|
|
|
vMap[k] = New(v)
|
|
|
|
}
|
|
|
|
return vMap
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MapDeep converts and returns <v> as map[string]interface{} recursively.
|
2020-06-16 17:38:05 +08:00
|
|
|
func (v *VarImp) MapDeep(tags ...string) map[string]interface{} {
|
2020-05-04 23:42:51 +08:00
|
|
|
return gconv.MapDeep(v.Val(), tags...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MapDeep converts and returns <v> as map[string]string recursively.
|
2020-06-16 17:38:05 +08:00
|
|
|
func (v *VarImp) MapStrStrDeep(tags ...string) map[string]string {
|
2020-05-04 23:42:51 +08:00
|
|
|
return gconv.MapStrStrDeep(v.Val(), tags...)
|
|
|
|
}
|
|
|
|
|
2020-06-16 17:38:05 +08:00
|
|
|
// MapStrVarDeep converts and returns <v> as map[string]*VarImp recursively.
|
|
|
|
func (v *VarImp) MapStrVarDeep(tags ...string) map[string]Var {
|
2020-05-04 23:42:51 +08:00
|
|
|
m := v.MapDeep(tags...)
|
|
|
|
if len(m) > 0 {
|
2020-06-16 17:38:05 +08:00
|
|
|
vMap := make(map[string]Var, len(m))
|
2020-05-04 23:42:51 +08:00
|
|
|
for k, v := range m {
|
|
|
|
vMap[k] = New(v)
|
|
|
|
}
|
|
|
|
return vMap
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Maps converts and returns <v> as map[string]string.
|
|
|
|
// See gconv.Maps.
|
2020-06-16 17:38:05 +08:00
|
|
|
func (v *VarImp) Maps(tags ...string) []map[string]interface{} {
|
2020-05-04 23:42:51 +08:00
|
|
|
return gconv.Maps(v.Val(), tags...)
|
|
|
|
}
|
|
|
|
|
2020-05-17 18:16:26 +08:00
|
|
|
// MapToMap converts any map type variable <params> to another map type variable <pointer>.
|
2020-05-04 23:42:51 +08:00
|
|
|
// See gconv.MapToMap.
|
2020-06-16 17:38:05 +08:00
|
|
|
func (v *VarImp) MapToMap(pointer interface{}, mapping ...map[string]string) (err error) {
|
|
|
|
return gconv.MapToMap(v.Val(), pointer, mapping...)
|
2020-05-04 23:42:51 +08:00
|
|
|
}
|
|
|
|
|
2020-05-17 18:16:26 +08:00
|
|
|
// MapToMapDeep converts any map type variable <params> to another map type variable
|
2020-05-04 23:42:51 +08:00
|
|
|
// <pointer> recursively.
|
|
|
|
// See gconv.MapToMapDeep.
|
2020-06-16 17:38:05 +08:00
|
|
|
func (v *VarImp) MapToMapDeep(pointer interface{}, mapping ...map[string]string) (err error) {
|
|
|
|
return gconv.MapToMapDeep(v.Val(), pointer, mapping...)
|
2020-05-04 23:42:51 +08:00
|
|
|
}
|
|
|
|
|
2020-05-17 18:16:26 +08:00
|
|
|
// MapToMaps converts any map type variable <params> to another map type variable <pointer>.
|
2020-05-04 23:42:51 +08:00
|
|
|
// See gconv.MapToMaps.
|
2020-06-16 17:38:05 +08:00
|
|
|
func (v *VarImp) MapToMaps(pointer interface{}, mapping ...map[string]string) (err error) {
|
2020-05-04 23:42:51 +08:00
|
|
|
return gconv.MapToMaps(v.Val(), pointer, mapping...)
|
|
|
|
}
|
|
|
|
|
2020-05-17 18:16:26 +08:00
|
|
|
// MapToMapsDeep converts any map type variable <params> to another map type variable
|
2020-05-04 23:42:51 +08:00
|
|
|
// <pointer> recursively.
|
|
|
|
// See gconv.MapToMapsDeep.
|
2020-06-16 17:38:05 +08:00
|
|
|
func (v *VarImp) MapToMapsDeep(pointer interface{}, mapping ...map[string]string) (err error) {
|
2020-05-04 23:42:51 +08:00
|
|
|
return gconv.MapToMapsDeep(v.Val(), pointer, mapping...)
|
|
|
|
}
|