Trying to figure out this dang thing

This commit is contained in:
Brian Buller 2023-06-15 09:53:59 -05:00
parent c64bda66f5
commit 638cf4ded7

View File

@ -15,7 +15,9 @@ func (b *DB) Load(path []string, dest any) error {
return errors.New("Destination must be a pointer") return errors.New("Destination must be a pointer")
} }
d := reflect.Indirect(destValue) d := reflect.Indirect(destValue)
fmt.Println(">> d.Kind() ->", d.Kind())
if d.Kind() != reflect.Struct { if d.Kind() != reflect.Struct {
fmt.Println(">> Kind != Struct; GetForInterface")
path, name := path[:len(path)-1], path[len(path)-1] path, name := path[:len(path)-1], path[len(path)-1]
return b.GetForInterface(path, name, dest) 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()) fmt.Println("Loading Field:", fldName, "->", structFld.Type.Kind())
switch structFld.Type.Kind() { switch structFld.Type.Kind() {
case reflect.Pointer, reflect.Struct: case reflect.Pointer, reflect.Struct:
fmt.Println("Getting Pointer or Struct")
var wrk interface{} var wrk interface{}
var wrkV reflect.Value var wrkV reflect.Value
if structFld.Type.Kind() == reflect.Pointer { if structFld.Type.Kind() == reflect.Pointer {
fmt.Println(" It's a pointer to something") fmt.Println(" It's a pointer to something")
wrkV = reflect.New(structFld).Type() wrkV = reflect.New(structFld.Type).Elem()
} else { } else {
fmt.Println(" It's a struct itself") fmt.Println(" It's a struct itself")
wrkV = reflect.New(reflect.TypeOf(structFld)) 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)) fmt.Println("-> Recurse (struct)", reflect.TypeOf(wrk))
err := b.Load(append(path, fldName), &wrk) err := b.Load(append(path, fldName), &wrk)
if err != nil { if err != nil {
fmt.Println("-> -> Error loading.", err.Error())
if ret == nil { if ret == nil {
ret = err ret = err
} }
@ -50,6 +54,7 @@ func (b *DB) Load(path []string, dest any) error {
} }
case reflect.String: case reflect.String:
fmt.Println("Getting String")
var wrk string var wrk string
err := b.GetForInterface(path, fldName, &wrk) err := b.GetForInterface(path, fldName, &wrk)
if err != nil { if err != nil {
@ -62,6 +67,7 @@ func (b *DB) Load(path []string, dest any) error {
} }
case reflect.Bool: case reflect.Bool:
fmt.Println("Getting Boolean")
var wrk bool var wrk bool
err := b.GetForInterface(path, fldName, &wrk) err := b.GetForInterface(path, fldName, &wrk)
if err != nil { 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: case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
fmt.Println("Getting Integer")
var wrk int var wrk int
err := b.GetForInterface(path, fldName, &wrk) err := b.GetForInterface(path, fldName, &wrk)
if err != nil { if err != nil {