Skip to content

Commit

Permalink
Merge pull request #61 from rafaelhl/skip-ignored-private-field
Browse files Browse the repository at this point in the history
Skip ignored private fields
  • Loading branch information
magiconair authored Dec 7, 2024
2 parents d80fb15 + 9c90def commit d8bdba3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ func dec(p *Properties, key string, def *string, opts map[string]string, v refle
for i := 0; i < v.NumField(); i++ {
fv := v.Field(i)
fk, def, opts := keydef(t.Field(i))
if !fv.CanSet() {
return fmt.Errorf("cannot set %s", t.Field(i).Name)
}
if fk == "-" {
continue
}
if !fv.CanSet() {
return fmt.Errorf("cannot set %s", t.Field(i).Name)
}
if key != "" {
fk = key + "." + fk
}
Expand Down
3 changes: 2 additions & 1 deletion decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,12 @@ func TestDecodeArrayDefaults(t *testing.T) {

func TestDecodeSkipUndef(t *testing.T) {
type S struct {
p string `properties:"-"`
X string `properties:"-"`
Undef string `properties:",default=some value"`
}
in := `X=ignore`
out := &S{"", "some value"}
out := &S{"", "", "some value"}
testDecode(t, in, &S{}, out)
}

Expand Down

0 comments on commit d8bdba3

Please sign in to comment.