diff --git a/env.go b/env.go index fa4ddb9..54af9e6 100644 --- a/env.go +++ b/env.go @@ -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 diff --git a/env_test.go b/env_test.go index 29b366e..5dd987b 100644 --- a/env_test.go +++ b/env_test.go @@ -31,6 +31,7 @@ type Config struct { type ParentStruct struct { InnerStruct *InnerStruct + unexported *InnerStruct } type InnerStruct struct { @@ -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{}