gvar_map.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. package gvar
  7. import "github.com/gogf/gf/util/gconv"
  8. // Map converts and returns `v` as map[string]interface{}.
  9. func (v *Var) Map(tags ...string) map[string]interface{} {
  10. return gconv.Map(v.Val(), tags...)
  11. }
  12. // MapStrAny is like function Map, but implements the interface of MapStrAny.
  13. func (v *Var) MapStrAny() map[string]interface{} {
  14. return v.Map()
  15. }
  16. // MapStrStr converts and returns `v` as map[string]string.
  17. func (v *Var) MapStrStr(tags ...string) map[string]string {
  18. return gconv.MapStrStr(v.Val(), tags...)
  19. }
  20. // MapStrVar converts and returns `v` as map[string]Var.
  21. func (v *Var) MapStrVar(tags ...string) map[string]*Var {
  22. m := v.Map(tags...)
  23. if len(m) > 0 {
  24. vMap := make(map[string]*Var, len(m))
  25. for k, v := range m {
  26. vMap[k] = New(v)
  27. }
  28. return vMap
  29. }
  30. return nil
  31. }
  32. // MapDeep converts and returns `v` as map[string]interface{} recursively.
  33. func (v *Var) MapDeep(tags ...string) map[string]interface{} {
  34. return gconv.MapDeep(v.Val(), tags...)
  35. }
  36. // MapStrStrDeep converts and returns `v` as map[string]string recursively.
  37. func (v *Var) MapStrStrDeep(tags ...string) map[string]string {
  38. return gconv.MapStrStrDeep(v.Val(), tags...)
  39. }
  40. // MapStrVarDeep converts and returns `v` as map[string]*Var recursively.
  41. func (v *Var) MapStrVarDeep(tags ...string) map[string]*Var {
  42. m := v.MapDeep(tags...)
  43. if len(m) > 0 {
  44. vMap := make(map[string]*Var, len(m))
  45. for k, v := range m {
  46. vMap[k] = New(v)
  47. }
  48. return vMap
  49. }
  50. return nil
  51. }
  52. // Maps converts and returns `v` as map[string]string.
  53. // See gconv.Maps.
  54. func (v *Var) Maps(tags ...string) []map[string]interface{} {
  55. return gconv.Maps(v.Val(), tags...)
  56. }
  57. // MapsDeep converts `value` to []map[string]interface{} recursively.
  58. // See gconv.MapsDeep.
  59. func (v *Var) MapsDeep(tags ...string) []map[string]interface{} {
  60. return gconv.MapsDeep(v.Val(), tags...)
  61. }
  62. // MapToMap converts any map type variable `params` to another map type variable `pointer`.
  63. // See gconv.MapToMap.
  64. func (v *Var) MapToMap(pointer interface{}, mapping ...map[string]string) (err error) {
  65. return gconv.MapToMap(v.Val(), pointer, mapping...)
  66. }
  67. // MapToMaps converts any map type variable `params` to another map type variable `pointer`.
  68. // See gconv.MapToMaps.
  69. func (v *Var) MapToMaps(pointer interface{}, mapping ...map[string]string) (err error) {
  70. return gconv.MapToMaps(v.Val(), pointer, mapping...)
  71. }
  72. // MapToMapsDeep converts any map type variable `params` to another map type variable
  73. // `pointer` recursively.
  74. // See gconv.MapToMapsDeep.
  75. func (v *Var) MapToMapsDeep(pointer interface{}, mapping ...map[string]string) (err error) {
  76. return gconv.MapToMaps(v.Val(), pointer, mapping...)
  77. }