Skip to content

Allow override of lookupEnv for _FILE support#210

Open
MaxJa4 wants to merge 1 commit intokelseyhightower:masterfrom
offen:expose_lookup_func
Open

Allow override of lookupEnv for _FILE support#210
MaxJa4 wants to merge 1 commit intokelseyhightower:masterfrom
offen:expose_lookup_func

Conversation

@MaxJa4
Copy link

@MaxJa4 MaxJa4 commented Aug 29, 2023

Closes #130

Exposing Lookup to the user enables them to use a custom LookupEnv function.
This way, any custom logic like the _FILE convention mentioned in #130 can be supported on the application side.

Example taken and adapted from offen/docker-volume-backup:

envconfig.Lookup = func(key string) (string, bool) {
    location, ok := os.LookupEnv(key + "_FILE")
    if ok {
        contents, err := os.ReadFile(location)
        if err != nil {
            return "", false
        }
        return string(contents), true
    }
    return os.LookupEnv(key)
}

if err := envconfig.Process("", &config); err != nil {
    panic(err)
}
...

@KenxinKun
Copy link

Any chance of this getting merged? I'd really could use this in my testing framework :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support emerging _FILE convention

2 participants