Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion env.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func get(fieldParams FieldParams, opts Options) (val string, err error) {
val = os.Expand(val, opts.getRawEnv)
}

opts.rawEnvVars[fieldParams.OwnKey] = val
opts.rawEnvVars[fieldParams.Key] = val

if fieldParams.Unset {
defer os.Unsetenv(fieldParams.Key)
Expand Down
7 changes: 7 additions & 0 deletions env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,12 @@ func TestParseExpandOption(t *testing.T) {
ExpandKey string `env:"EXPAND_KEY"`
CompoundKey string `env:"HOST_PORT,expand" envDefault:"${HOST}:${PORT}"`
Default string `env:"DEFAULT,expand" envDefault:"def1"`
Component struct {
Port int `env:"PORT" envDefault:"5000"`
Internal struct {
Host string `env:"INTERNAL_HOST,expand" envDefault:"${HOST}:${COMPONENT_PORT}"`
}
} `envPrefix:"COMPONENT_"`
}

t.Setenv("HOST", "localhost")
Expand All @@ -1008,6 +1014,7 @@ func TestParseExpandOption(t *testing.T) {
isEqual(t, "qwerty12345", cfg.ExpandKey)
isEqual(t, "localhost:3000", cfg.CompoundKey)
isEqual(t, "def1", cfg.Default)
isEqual(t, "localhost:5000", cfg.Component.Internal.Host)
}

func TestParseExpandWithDefaultOption(t *testing.T) {
Expand Down
Loading