diff --git a/env.go b/env.go index 7dc85ab..1a8b30b 100644 --- a/env.go +++ b/env.go @@ -221,8 +221,9 @@ func checkEnv(envName, fieldName string, fieldValue reflect.Value) *string { func SetFromEnv(prefix string, s interface{}) []error { return setFromEnv(nil, prefix, s) } + func setFromEnv(allErrors []error, prefix string, s interface{}) []error { - // TOOD: this is quite similar in structure to structToEnvVars() - can it be refactored with + // TODO: this is quite similar in structure to structToEnvVars() - can it be refactored with // passing setter vs getter function and share the same iteration (yet a little bit of copy is the go way too) v := reflect.ValueOf(s) // if we're passed a pointer to a struct instead of the struct, let that work too diff --git a/env_test.go b/env_test.go index ea35efd..917e7fb 100644 --- a/env_test.go +++ b/env_test.go @@ -186,7 +186,10 @@ func TestSetFromEnv(t *testing.T) { for _, e := range envs { os.Setenv(e.k, e.v) } - struct2env.SetFromEnv("TST2_", &foo) + errors := struct2env.SetFromEnv("TST2_", &foo) + if len(errors) != 0 { + t.Errorf("Unexpectedly got errors :%v", errors) + } assert.Equal(t, foo.Foo, "another\nfoo") assert.Equal(t, foo.Bar, "bar") assert.Equal(t, foo.RecurseHere.InnerB, "in1")