add and improve Scan/ScanDeep feature for package gdb/gvar/gjson/gconv

This commit is contained in:
John
2020-06-15 16:46:48 +08:00
parent 49d1e3dbaf
commit 508cb7db88
6 changed files with 283 additions and 8 deletions

View File

@ -6,7 +6,9 @@
package gvar
import "github.com/gogf/gf/util/gconv"
import (
"github.com/gogf/gf/util/gconv"
)
// Struct maps value of <v> to <pointer>.
// The parameter <pointer> should be a pointer to a struct instance.
@ -31,3 +33,19 @@ func (v *Var) Structs(pointer interface{}, mapping ...map[string]string) (err er
func (v *Var) StructsDeep(pointer interface{}, mapping ...map[string]string) (err error) {
return gconv.StructsDeep(v.Val(), pointer, mapping...)
}
// Scan automatically calls Struct or Structs function according to the type of parameter
// <pointer> to implement the converting.
// It calls function Struct if <pointer> is type of *struct/**struct to do the converting.
// It calls function Structs if <pointer> is type of *[]struct/*[]*struct to do the converting.
func (v *Var) Scan(pointer interface{}, mapping ...map[string]string) (err error) {
return gconv.Scan(v.Val(), pointer, mapping...)
}
// ScanDeep automatically calls StructDeep or StructsDeep function according to the type of
// parameter <pointer> to implement the converting.
// It calls function StructDeep if <pointer> is type of *struct/**struct to do the converting.
// It calls function StructsDeep if <pointer> is type of *[]struct/*[]*struct to do the converting.
func (v *Var) ScanDeep(pointer interface{}, mapping ...map[string]string) (err error) {
return gconv.ScanDeep(v.Val(), pointer, mapping...)
}