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