|
@@ -3,7 +3,6 @@ package rest
|
|
|
import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
- "log"
|
|
|
"reflect"
|
|
|
"strings"
|
|
|
|
|
@@ -172,6 +171,9 @@ func parseName(val reflect.Value) (res *Field, err error) {
|
|
|
|
|
|
func StructTypeName(val reflect.Value) string {
|
|
|
t := val.Type()
|
|
|
+ if t.Kind() == reflect.Pointer {
|
|
|
+ t = t.Elem()
|
|
|
+ }
|
|
|
return t.PkgPath() + "." + t.Name()
|
|
|
}
|
|
|
|
|
@@ -239,7 +241,11 @@ func fieldVal(val reflect.Value, fieldName string, files RequestFiles, names Fie
|
|
|
stn := StructTypeName(field)
|
|
|
con, check := fieldConverters[stn]
|
|
|
if check {
|
|
|
- jm[name.Name] = con.Pack(field.Interface())
|
|
|
+ if field.Kind() == reflect.Ptr {
|
|
|
+ jm[name.Name] = con.Pack(field.Elem().Interface())
|
|
|
+ } else {
|
|
|
+ jm[name.Name] = con.Pack(field.Interface())
|
|
|
+ }
|
|
|
} else {
|
|
|
jm[name.Name] = fVal.Interface()
|
|
|
}
|
|
@@ -321,8 +327,10 @@ func FieldsAny(obj any, files RequestFiles, names FieldList) (any, IErrorArgs) {
|
|
|
// Fields позволяет получить значения объекта в json
|
|
|
func Fields(obj any, files RequestFiles, names FieldList) (json.Map, IErrorArgs) {
|
|
|
sVal := reflect.ValueOf(obj)
|
|
|
- log.Println(sVal)
|
|
|
- rVal, err := fieldVal(sVal.Elem(), "", files, names)
|
|
|
+ if sVal.Kind() == reflect.Pointer {
|
|
|
+ sVal = sVal.Elem()
|
|
|
+ }
|
|
|
+ rVal, err := fieldVal(sVal, "", files, names)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|