Trying to figure out this dang thing
This commit is contained in:
parent
c64bda66f5
commit
638cf4ded7
@ -15,7 +15,9 @@ func (b *DB) Load(path []string, dest any) error {
|
||||
return errors.New("Destination must be a pointer")
|
||||
}
|
||||
d := reflect.Indirect(destValue)
|
||||
fmt.Println(">> d.Kind() ->", d.Kind())
|
||||
if d.Kind() != reflect.Struct {
|
||||
fmt.Println(">> Kind != Struct; GetForInterface")
|
||||
path, name := path[:len(path)-1], path[len(path)-1]
|
||||
return b.GetForInterface(path, name, dest)
|
||||
}
|
||||
@ -28,11 +30,12 @@ func (b *DB) Load(path []string, dest any) error {
|
||||
fmt.Println("Loading Field:", fldName, "->", structFld.Type.Kind())
|
||||
switch structFld.Type.Kind() {
|
||||
case reflect.Pointer, reflect.Struct:
|
||||
fmt.Println("Getting Pointer or Struct")
|
||||
var wrk interface{}
|
||||
var wrkV reflect.Value
|
||||
if structFld.Type.Kind() == reflect.Pointer {
|
||||
fmt.Println(" It's a pointer to something")
|
||||
wrkV = reflect.New(structFld).Type()
|
||||
wrkV = reflect.New(structFld.Type).Elem()
|
||||
} else {
|
||||
fmt.Println(" It's a struct itself")
|
||||
wrkV = reflect.New(reflect.TypeOf(structFld))
|
||||
@ -41,6 +44,7 @@ func (b *DB) Load(path []string, dest any) error {
|
||||
fmt.Println("-> Recurse (struct)", reflect.TypeOf(wrk))
|
||||
err := b.Load(append(path, fldName), &wrk)
|
||||
if err != nil {
|
||||
fmt.Println("-> -> Error loading.", err.Error())
|
||||
if ret == nil {
|
||||
ret = err
|
||||
}
|
||||
@ -50,6 +54,7 @@ func (b *DB) Load(path []string, dest any) error {
|
||||
}
|
||||
|
||||
case reflect.String:
|
||||
fmt.Println("Getting String")
|
||||
var wrk string
|
||||
err := b.GetForInterface(path, fldName, &wrk)
|
||||
if err != nil {
|
||||
@ -62,6 +67,7 @@ func (b *DB) Load(path []string, dest any) error {
|
||||
}
|
||||
|
||||
case reflect.Bool:
|
||||
fmt.Println("Getting Boolean")
|
||||
var wrk bool
|
||||
err := b.GetForInterface(path, fldName, &wrk)
|
||||
if err != nil {
|
||||
@ -74,6 +80,7 @@ func (b *DB) Load(path []string, dest any) error {
|
||||
}
|
||||
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
fmt.Println("Getting Integer")
|
||||
var wrk int
|
||||
err := b.GetForInterface(path, fldName, &wrk)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user