Skip to content

Commit cbddc98

Browse files
authored
Merge pull request #73 from MDobak/master
Ignore unexported fields that are not embedded structs
2 parents 3502e48 + d32ab46 commit cbddc98

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

struct_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import (
1212
)
1313

1414
type structUserForTest struct {
15-
ID int `db:"id" fieldtag:"important"`
16-
Name string `fieldtag:"important"`
17-
Status int `db:"status" fieldtag:"important"`
18-
CreatedAt int `db:"created_at"`
15+
ID int `db:"id" fieldtag:"important"`
16+
Name string `fieldtag:"important"`
17+
Status int `db:"status" fieldtag:"important"`
18+
CreatedAt int `db:"created_at"`
19+
unexported struct{}
1920
}
2021

2122
var userForTest = NewStruct(new(structUserForTest))

structfields.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ func (sf *structFields) parse(t reflect.Type, mapper FieldMapperFunc, prefix str
5151
for i := 0; i < l; i++ {
5252
field := t.Field(i)
5353

54+
// Skip unexported fields that are not embedded structs.
55+
if !field.IsExported() && !field.Anonymous {
56+
continue
57+
}
58+
5459
if field.Anonymous {
5560
ft := field.Type
5661

0 commit comments

Comments
 (0)