Skip to content

Envconfig not respecting Prefix #148

@jakubdyszkiewicz

Description

@jakubdyszkiewicz

Consider such struct

type Something struct {
	User string `envconfig:"user"`
}
something := Something{}
err := envconfig.Process("my_app", &something)

I'd expect that if MY_APP_USER env is not set, the something.User will be empty, but that's not the case. Due to this line https://github.com/kelseyhightower/envconfig/blob/master/envconfig.go#L99 the Alt is set to user. Process method https://github.com/kelseyhightower/envconfig/blob/master/envconfig.go#L195 first try to find by Key (which is MY_APP_USER), but then by Alt, so when MY_APP_USER is not available, then the USER is looked up. On MacOS USER this is set to your username, so instead of empty string I see my username.

Is this expected behaviour?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions