github.com/gogf/gf@v1.16.9/container/gvar/gvar_map.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package gvar 8 9 import "github.com/gogf/gf/util/gconv" 10 11 // Map converts and returns `v` as map[string]interface{}. 12 func (v *Var) Map(tags ...string) map[string]interface{} { 13 return gconv.Map(v.Val(), tags...) 14 } 15 16 // MapStrAny is like function Map, but implements the interface of MapStrAny. 17 func (v *Var) MapStrAny() map[string]interface{} { 18 return v.Map() 19 } 20 21 // MapStrStr converts and returns `v` as map[string]string. 22 func (v *Var) MapStrStr(tags ...string) map[string]string { 23 return gconv.MapStrStr(v.Val(), tags...) 24 } 25 26 // MapStrVar converts and returns `v` as map[string]Var. 27 func (v *Var) MapStrVar(tags ...string) map[string]*Var { 28 m := v.Map(tags...) 29 if len(m) > 0 { 30 vMap := make(map[string]*Var, len(m)) 31 for k, v := range m { 32 vMap[k] = New(v) 33 } 34 return vMap 35 } 36 return nil 37 } 38 39 // MapDeep converts and returns `v` as map[string]interface{} recursively. 40 func (v *Var) MapDeep(tags ...string) map[string]interface{} { 41 return gconv.MapDeep(v.Val(), tags...) 42 } 43 44 // MapStrStrDeep converts and returns `v` as map[string]string recursively. 45 func (v *Var) MapStrStrDeep(tags ...string) map[string]string { 46 return gconv.MapStrStrDeep(v.Val(), tags...) 47 } 48 49 // MapStrVarDeep converts and returns `v` as map[string]*Var recursively. 50 func (v *Var) MapStrVarDeep(tags ...string) map[string]*Var { 51 m := v.MapDeep(tags...) 52 if len(m) > 0 { 53 vMap := make(map[string]*Var, len(m)) 54 for k, v := range m { 55 vMap[k] = New(v) 56 } 57 return vMap 58 } 59 return nil 60 } 61 62 // Maps converts and returns `v` as map[string]string. 63 // See gconv.Maps. 64 func (v *Var) Maps(tags ...string) []map[string]interface{} { 65 return gconv.Maps(v.Val(), tags...) 66 } 67 68 // MapsDeep converts `value` to []map[string]interface{} recursively. 69 // See gconv.MapsDeep. 70 func (v *Var) MapsDeep(tags ...string) []map[string]interface{} { 71 return gconv.MapsDeep(v.Val(), tags...) 72 } 73 74 // MapToMap converts any map type variable `params` to another map type variable `pointer`. 75 // See gconv.MapToMap. 76 func (v *Var) MapToMap(pointer interface{}, mapping ...map[string]string) (err error) { 77 return gconv.MapToMap(v.Val(), pointer, mapping...) 78 } 79 80 // MapToMaps converts any map type variable `params` to another map type variable `pointer`. 81 // See gconv.MapToMaps. 82 func (v *Var) MapToMaps(pointer interface{}, mapping ...map[string]string) (err error) { 83 return gconv.MapToMaps(v.Val(), pointer, mapping...) 84 } 85 86 // MapToMapsDeep converts any map type variable `params` to another map type variable 87 // `pointer` recursively. 88 // See gconv.MapToMapsDeep. 89 func (v *Var) MapToMapsDeep(pointer interface{}, mapping ...map[string]string) (err error) { 90 return gconv.MapToMaps(v.Val(), pointer, mapping...) 91 }