refactor: split dbx package into domain files
Reorganize monolithic dbx.go and utility.go into focused files by concern, add package doc.go, and gitignore coverage.out. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package dbx
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"gitea.auvem.com/go-toolkit/dbx/internal/dbxshared"
|
||||
)
|
||||
|
||||
// DestName returns the name of the type passed as `destTypeStruct` as a string,
|
||||
// normalized for compatibility with the Jet QRM.
|
||||
func DestName(destTypeStruct any, path ...string) string {
|
||||
v := reflect.ValueOf(destTypeStruct)
|
||||
for v.Kind() == reflect.Pointer {
|
||||
v = v.Elem()
|
||||
}
|
||||
|
||||
destIdent := v.Type().String()
|
||||
destIdent = destIdent[strings.LastIndex(destIdent, ".")+1:]
|
||||
|
||||
for i, p := range path {
|
||||
if v.Kind() != reflect.Struct {
|
||||
dbxshared.DBModule.Logger().Error("DestName: path parent is not a struct", "path", destIdent+"."+strings.Join(path[:i+1], "."))
|
||||
return ""
|
||||
}
|
||||
|
||||
v = v.FieldByName(p)
|
||||
|
||||
if !v.IsValid() {
|
||||
dbxshared.DBModule.Logger().Error("DestName: field does not exist", "path", destIdent+"."+strings.Join(path[:i+1], "."))
|
||||
return ""
|
||||
}
|
||||
|
||||
destIdent += "." + p
|
||||
}
|
||||
|
||||
return destIdent
|
||||
}
|
||||
Reference in New Issue
Block a user