ignore unexported fields that are not embedded structs

This commit is contained in:
Michał Dobaczewski
2022-06-07 13:15:06 +02:00
parent 68495078ea
commit c1d29073e0
2 changed files with 10 additions and 4 deletions
+5 -4
View File
@@ -12,10 +12,11 @@ import (
)
type structUserForTest struct {
ID int `db:"id" fieldtag:"important"`
Name string `fieldtag:"important"`
Status int `db:"status" fieldtag:"important"`
CreatedAt int `db:"created_at"`
ID int `db:"id" fieldtag:"important"`
Name string `fieldtag:"important"`
Status int `db:"status" fieldtag:"important"`
CreatedAt int `db:"created_at"`
unexported struct{}
}
var userForTest = NewStruct(new(structUserForTest))
+5
View File
@@ -51,6 +51,11 @@ func (sf *structFields) parse(t reflect.Type, mapper FieldMapperFunc, prefix str
for i := 0; i < l; i++ {
field := t.Field(i)
// Skip unexported fields that are not embedded structs.
if !field.IsExported() && !field.Anonymous {
continue
}
if field.Anonymous {
ft := field.Type