improved getStructFields: for anonymous field that is not struct.

testCase:
type DurationInSeconds struct {
    time.Duration
}
func(dis DurationInSeconds) func1() {}
func(dis DurationInSeconds) func2() {}
This commit is contained in:
DESKTOP-NJM1EHE\vlad
2019-02-02 21:55:42 +02:00
parent 60711f1a83
commit 9dbc6d1bf9
+12 -5
View File
@@ -341,6 +341,7 @@ func getStructFields(t reflect.Type) ([]reflect.StructField, error) {
}
var efields []reflect.StructField
var fields []reflect.StructField
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
if !f.Anonymous {
@@ -352,14 +353,20 @@ func getStructFields(t reflect.Type) ([]reflect.StructField, error) {
t1 = t1.Elem()
}
fs, err := getStructFields(t1)
if err != nil {
return nil, fmt.Errorf("error processing embedded field: %v", err)
if t1.Kind() == reflect.Struct {
fs, err := getStructFields(t1)
if err != nil {
return nil, fmt.Errorf("error processing embedded field: %v", err)
}
efields = mergeStructFields(efields, fs)
} else {
if strings.Contains(f.Name, ".") || unicode.IsUpper([]rune(f.Name)[0]) {
fields = append(fields, f)
}
}
efields = mergeStructFields(efields, fs)
}
var fields []reflect.StructField
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
if f.Anonymous {