github.com/gogf/gf@v1.16.9/container/gvar/gvar_struct.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 (
    10  	"github.com/gogf/gf/util/gconv"
    11  )
    12  
    13  // Struct maps value of `v` to `pointer`.
    14  // The parameter `pointer` should be a pointer to a struct instance.
    15  // The parameter `mapping` is used to specify the key-to-attribute mapping rules.
    16  func (v *Var) Struct(pointer interface{}, mapping ...map[string]string) error {
    17  	return gconv.Struct(v.Val(), pointer, mapping...)
    18  }
    19  
    20  // StructDeep maps value of `v` to `pointer` recursively.
    21  // The parameter `pointer` should be a pointer to a struct instance.
    22  // The parameter `mapping` is used to specify the key-to-attribute mapping rules.
    23  // Deprecated, use Struct instead.
    24  func (v *Var) StructDeep(pointer interface{}, mapping ...map[string]string) error {
    25  	return gconv.StructDeep(v.Val(), pointer, mapping...)
    26  }
    27  
    28  // Structs converts and returns `v` as given struct slice.
    29  func (v *Var) Structs(pointer interface{}, mapping ...map[string]string) error {
    30  	return gconv.Structs(v.Val(), pointer, mapping...)
    31  }
    32  
    33  // StructsDeep converts and returns `v` as given struct slice recursively.
    34  // Deprecated, use Struct instead.
    35  func (v *Var) StructsDeep(pointer interface{}, mapping ...map[string]string) error {
    36  	return gconv.StructsDeep(v.Val(), pointer, mapping...)
    37  }
    38  
    39  // Scan automatically calls Struct or Structs function according to the type of parameter
    40  // `pointer` to implement the converting.
    41  //
    42  // It calls function Struct if `pointer` is type of *struct/**struct to do the converting.
    43  // It calls function Structs if `pointer` is type of *[]struct/*[]*struct to do the converting.
    44  func (v *Var) Scan(pointer interface{}, mapping ...map[string]string) error {
    45  	return gconv.Scan(v.Val(), pointer, mapping...)
    46  }
    47  
    48  // ScanDeep automatically calls StructDeep or StructsDeep function according to the type of
    49  // parameter `pointer` to implement the converting.
    50  //
    51  // It calls function StructDeep if `pointer` is type of *struct/**struct to do the converting.
    52  // It calls function StructsDeep if `pointer` is type of *[]struct/*[]*struct to do the converting.
    53  //
    54  // Deprecated, use Scan instead.
    55  func (v *Var) ScanDeep(pointer interface{}, mapping ...map[string]string) error {
    56  	return gconv.ScanDeep(v.Val(), pointer, mapping...)
    57  }