Skip to content

Commit

Permalink
Merge pull request #40 from caarlos0/fix
Browse files Browse the repository at this point in the history
fix unexported inner structs
  • Loading branch information
caarlos0 committed Oct 30, 2017
2 parents d29d8d2 + cb3993a commit 9de094f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion env.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func doParse(ref reflect.Value) error {
var errorList []string

for i := 0; i < refType.NumField(); i++ {
if reflect.Ptr == ref.Field(i).Kind() {
if reflect.Ptr == ref.Field(i).Kind() && ref.Field(i).CanSet() {
err := Parse(ref.Field(i).Interface())
if nil != err {
return err
Expand Down
5 changes: 2 additions & 3 deletions env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Config struct {

type ParentStruct struct {
InnerStruct *InnerStruct
unexported *InnerStruct
}

type InnerStruct struct {
Expand Down Expand Up @@ -77,16 +78,14 @@ func TestParsesEnv(t *testing.T) {
}

func TestParsesEnvInner(t *testing.T) {

os.Setenv("innervar", "someinnervalue")
defer os.Clearenv()
cfg := ParentStruct{&InnerStruct{}}
cfg := ParentStruct{&InnerStruct{}, &InnerStruct{}}
assert.NoError(t, env.Parse(&cfg))
assert.Equal(t, "someinnervalue", cfg.InnerStruct.Inner)
}

func TestParsesEnvInnerNil(t *testing.T) {

os.Setenv("innervar", "someinnervalue")
defer os.Clearenv()
cfg := ParentStruct{}
Expand Down

0 comments on commit 9de094f

Please sign in to comment.