Merge pull request #73 from MDobak/master

Ignore unexported fields that are not embedded structs
This commit is contained in:
Huan Du
2022-06-23 13:24:50 +08:00
committed by GitHub
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