Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow override of lookupEnv for _FILE support #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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