gvar_struct.go 2.4 KB

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